laya.core.js 976 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649
  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, isformatURL) {
  18280. var _this = this;
  18281. isformatURL ? isformatURL : false;
  18282. if (isformatURL)
  18283. url = URL.formatURL(url);
  18284. var onLoaded;
  18285. var onError = function () {
  18286. _this.event(Event.ERROR, "Load image failed");
  18287. };
  18288. if (this._type === "nativeimage") {
  18289. onLoaded = function (image) {
  18290. _this.onLoaded(image);
  18291. };
  18292. this._loadHtmlImage(url, this, onLoaded, this, onError);
  18293. }
  18294. else {
  18295. var ext = Utils.getFileExtension(url);
  18296. if (ext === "ktx" || ext === "pvr") {
  18297. onLoaded = function (imageData) {
  18298. var format;
  18299. switch (ext) {
  18300. case "ktx":
  18301. format = 5;
  18302. break;
  18303. case "pvr":
  18304. format = 12;
  18305. break;
  18306. }
  18307. var tex = new Texture2D(0, 0, format, false, false);
  18308. tex.wrapModeU = BaseTexture.WARPMODE_CLAMP;
  18309. tex.wrapModeV = BaseTexture.WARPMODE_CLAMP;
  18310. tex.setCompressData(imageData);
  18311. tex._setCreateURL(url);
  18312. _this.onLoaded(tex);
  18313. };
  18314. this._loadHttpRequest(url, Loader.BUFFER, this, onLoaded, null, null, this, onError);
  18315. }
  18316. else {
  18317. onLoaded = function (image) {
  18318. var tex = new Texture2D(image.width, image.height, 1, false, false);
  18319. tex.wrapModeU = BaseTexture.WARPMODE_CLAMP;
  18320. tex.wrapModeV = BaseTexture.WARPMODE_CLAMP;
  18321. tex.loadImageSource(image, true);
  18322. tex._setCreateURL(url);
  18323. _this.onLoaded(tex);
  18324. };
  18325. this._loadHtmlImage(url, this, onLoaded, this, onError);
  18326. }
  18327. }
  18328. }
  18329. _loadSound(url) {
  18330. var sound = (new SoundManager._soundClass());
  18331. var _this = this;
  18332. sound.on(Event.COMPLETE, this, soundOnload);
  18333. sound.on(Event.ERROR, this, soundOnErr);
  18334. sound.load(url);
  18335. function soundOnload() {
  18336. clear();
  18337. _this.onLoaded(sound);
  18338. }
  18339. function soundOnErr() {
  18340. clear();
  18341. sound.dispose();
  18342. _this.event(Event.ERROR, "Load sound failed");
  18343. }
  18344. function clear() {
  18345. sound.offAll();
  18346. }
  18347. }
  18348. onProgress(value) {
  18349. if (this._type === Loader.ATLAS)
  18350. this.event(Event.PROGRESS, value * 0.3);
  18351. else
  18352. this.event(Event.PROGRESS, value);
  18353. }
  18354. onError(message) {
  18355. this.event(Event.ERROR, message);
  18356. }
  18357. onLoaded(data = null) {
  18358. var type = this._type;
  18359. if (type == Loader.PLFB) {
  18360. this.parsePLFBData(data);
  18361. this.complete(data);
  18362. }
  18363. else if (type == Loader.PLF) {
  18364. this.parsePLFData(data);
  18365. this.complete(data);
  18366. }
  18367. else if (type === Loader.IMAGE) {
  18368. var tex = new Texture(data);
  18369. tex.url = this._url;
  18370. this.complete(tex);
  18371. }
  18372. else if (type === Loader.SOUND || type === "htmlimage" || type === "nativeimage") {
  18373. this.complete(data);
  18374. }
  18375. else if (type === Loader.ATLAS) {
  18376. if (!(data instanceof Texture2D)) {
  18377. if (!this._data) {
  18378. this._data = data;
  18379. if (data.meta && data.meta.image) {
  18380. var toloadPics = data.meta.image.split(",");
  18381. var split = this._url.indexOf("/") >= 0 ? "/" : "\\";
  18382. var idx = this._url.lastIndexOf(split);
  18383. var folderPath = idx >= 0 ? this._url.substr(0, idx + 1) : "";
  18384. var changeType;
  18385. if (Browser.onAndroid && data.meta.compressTextureAndroid) {
  18386. changeType = ".ktx";
  18387. }
  18388. if (Browser.onIOS && data.meta.compressTextureIOS) {
  18389. changeType = ".pvr";
  18390. }
  18391. for (var i = 0, len = toloadPics.length; i < len; i++) {
  18392. if (changeType) {
  18393. toloadPics[i] = folderPath + toloadPics[i].replace(".png", changeType);
  18394. }
  18395. else {
  18396. toloadPics[i] = folderPath + toloadPics[i];
  18397. }
  18398. }
  18399. }
  18400. else {
  18401. toloadPics = [this._url.replace(".json", ".png")];
  18402. }
  18403. toloadPics.reverse();
  18404. data.toLoads = toloadPics;
  18405. data.pics = [];
  18406. }
  18407. this.event(Event.PROGRESS, 0.3 + 1 / toloadPics.length * 0.6);
  18408. return this._loadResourceFilter(Loader.IMAGE, toloadPics.pop());
  18409. }
  18410. else {
  18411. this._data.pics.push(data);
  18412. if (this._data.toLoads.length > 0) {
  18413. this.event(Event.PROGRESS, 0.3 + 1 / this._data.toLoads.length * 0.6);
  18414. return this._loadResourceFilter(Loader.IMAGE, this._data.toLoads.pop());
  18415. }
  18416. var frames = this._data.frames;
  18417. var cleanUrl = this._url.split("?")[0];
  18418. var directory = (this._data.meta && this._data.meta.prefix) ? this._data.meta.prefix : cleanUrl.substring(0, cleanUrl.lastIndexOf(".")) + "/";
  18419. var pics = this._data.pics;
  18420. var atlasURL = URL.formatURL(this._url);
  18421. var map = Loader.atlasMap[atlasURL] || (Loader.atlasMap[atlasURL] = []);
  18422. map.dir = directory;
  18423. var scaleRate = 1;
  18424. if (this._data.meta && this._data.meta.scale && this._data.meta.scale != 1) {
  18425. scaleRate = parseFloat(this._data.meta.scale);
  18426. for (var name in frames) {
  18427. var obj = frames[name];
  18428. var tPic = pics[obj.frame.idx ? obj.frame.idx : 0];
  18429. var url = URL.formatURL(directory + name);
  18430. tPic.scaleRate = scaleRate;
  18431. var tTexture;
  18432. 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));
  18433. Loader.cacheRes(url, tTexture);
  18434. tTexture.url = url;
  18435. map.push(url);
  18436. }
  18437. }
  18438. else {
  18439. for (name in frames) {
  18440. obj = frames[name];
  18441. tPic = pics[obj.frame.idx ? obj.frame.idx : 0];
  18442. url = URL.formatURL(directory + name);
  18443. 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));
  18444. Loader.cacheRes(url, tTexture);
  18445. tTexture.url = url;
  18446. map.push(url);
  18447. }
  18448. }
  18449. delete this._data.pics;
  18450. this.complete(this._data);
  18451. }
  18452. }
  18453. else if (type === Loader.FONT) {
  18454. if (!data._source) {
  18455. this._data = data;
  18456. this.event(Event.PROGRESS, 0.5);
  18457. return this._loadImage(this._url.replace(".fnt", ".png"));
  18458. }
  18459. else {
  18460. var bFont = new BitmapFont();
  18461. bFont.parseFont(this._data, new Texture(data));
  18462. var tArr = this._url.split(".fnt")[0].split("/");
  18463. var fontName = tArr[tArr.length - 1];
  18464. Text.registerBitmapFont(fontName, bFont);
  18465. this._data = bFont;
  18466. this.complete(this._data);
  18467. }
  18468. }
  18469. else if (type === Loader.PREFAB) {
  18470. var prefab = new Prefab();
  18471. prefab.json = data;
  18472. this.complete(prefab);
  18473. }
  18474. else {
  18475. this.complete(data);
  18476. }
  18477. }
  18478. parsePLFData(plfData) {
  18479. var type;
  18480. var filePath;
  18481. var fileDic;
  18482. for (type in plfData) {
  18483. fileDic = plfData[type];
  18484. switch (type) {
  18485. case "json":
  18486. case "text":
  18487. for (filePath in fileDic) {
  18488. Loader.preLoadedMap[URL.formatURL(filePath)] = fileDic[filePath];
  18489. }
  18490. break;
  18491. default:
  18492. for (filePath in fileDic) {
  18493. Loader.preLoadedMap[URL.formatURL(filePath)] = fileDic[filePath];
  18494. }
  18495. }
  18496. }
  18497. }
  18498. parsePLFBData(plfData) {
  18499. var byte;
  18500. byte = new Byte(plfData);
  18501. var i, len;
  18502. len = byte.getInt32();
  18503. for (i = 0; i < len; i++) {
  18504. this.parseOnePLFBFile(byte);
  18505. }
  18506. }
  18507. parseOnePLFBFile(byte) {
  18508. var fileLen;
  18509. var fileName;
  18510. var fileData;
  18511. fileName = byte.getUTFString();
  18512. fileLen = byte.getInt32();
  18513. fileData = byte.readArrayBuffer(fileLen);
  18514. Loader.preLoadedMap[URL.formatURL(fileName)] = fileData;
  18515. }
  18516. complete(data) {
  18517. this._data = data;
  18518. if (this._customParse) {
  18519. this.event(Event.LOADED, data instanceof Array ? [data] : data);
  18520. }
  18521. else {
  18522. Loader._loaders.push(this);
  18523. if (!Loader._isWorking)
  18524. Loader.checkNext();
  18525. }
  18526. }
  18527. static checkNext() {
  18528. Loader._isWorking = true;
  18529. var startTimer = Browser.now();
  18530. var thisTimer = startTimer;
  18531. while (Loader._startIndex < Loader._loaders.length) {
  18532. thisTimer = Browser.now();
  18533. Loader._loaders[Loader._startIndex].endLoad();
  18534. Loader._startIndex++;
  18535. if (Browser.now() - startTimer > Loader.maxTimeOut) {
  18536. console.warn("loader callback cost a long time:" + (Browser.now() - startTimer) + " url=" + Loader._loaders[Loader._startIndex - 1].url);
  18537. ILaya.systemTimer.frameOnce(1, null, Loader.checkNext);
  18538. return;
  18539. }
  18540. }
  18541. Loader._loaders.length = 0;
  18542. Loader._startIndex = 0;
  18543. Loader._isWorking = false;
  18544. }
  18545. endLoad(content = null) {
  18546. content && (this._data = content);
  18547. if (this._cache)
  18548. Loader.cacheRes(this._url, this._data);
  18549. this.event(Event.PROGRESS, 1);
  18550. this.event(Event.COMPLETE, this.data instanceof Array ? [this.data] : this.data);
  18551. }
  18552. get url() {
  18553. return this._url;
  18554. }
  18555. get type() {
  18556. return this._type;
  18557. }
  18558. get cache() {
  18559. return this._cache;
  18560. }
  18561. get data() {
  18562. return this._data;
  18563. }
  18564. static clearRes(url) {
  18565. url = URL.formatURL(url);
  18566. var arr = Loader.getAtlas(url);
  18567. if (arr) {
  18568. for (var i = 0, n = arr.length; i < n; i++) {
  18569. var resUrl = arr[i];
  18570. var tex = Loader.getRes(resUrl);
  18571. delete Loader.loadedMap[resUrl];
  18572. if (tex)
  18573. tex.destroy();
  18574. }
  18575. arr.length = 0;
  18576. delete Loader.atlasMap[url];
  18577. delete Loader.loadedMap[url];
  18578. }
  18579. else {
  18580. var res = Loader.loadedMap[url];
  18581. if (res) {
  18582. delete Loader.loadedMap[url];
  18583. if (res instanceof Texture && res.bitmap)
  18584. res.destroy();
  18585. }
  18586. }
  18587. }
  18588. static clearTextureRes(url) {
  18589. url = URL.formatURL(url);
  18590. var arr = Loader.getAtlas(url);
  18591. if (arr && arr.length > 0) {
  18592. arr.forEach(function (t) {
  18593. var tex = Loader.getRes(t);
  18594. if (tex instanceof Texture) {
  18595. tex.disposeBitmap();
  18596. }
  18597. });
  18598. }
  18599. else {
  18600. var t = Loader.getRes(url);
  18601. if (t instanceof Texture) {
  18602. t.disposeBitmap();
  18603. }
  18604. }
  18605. }
  18606. static getRes(url) {
  18607. return Loader.loadedMap[URL.formatURL(url)];
  18608. }
  18609. static getAtlas(url) {
  18610. return Loader.atlasMap[URL.formatURL(url)];
  18611. }
  18612. static cacheRes(url, data) {
  18613. url = URL.formatURL(url);
  18614. if (Loader.loadedMap[url] != null) {
  18615. console.warn("Resources already exist,is repeated loading:", url);
  18616. }
  18617. else {
  18618. Loader.loadedMap[url] = data;
  18619. }
  18620. }
  18621. static setGroup(url, group) {
  18622. if (!Loader.groupMap[group])
  18623. Loader.groupMap[group] = [];
  18624. Loader.groupMap[group].push(url);
  18625. }
  18626. static clearResByGroup(group) {
  18627. if (!Loader.groupMap[group])
  18628. return;
  18629. var arr = Loader.groupMap[group], i, len = arr.length;
  18630. for (i = 0; i < len; i++) {
  18631. Loader.clearRes(arr[i]);
  18632. }
  18633. arr.length = 0;
  18634. }
  18635. }
  18636. Loader.TEXT = "text";
  18637. Loader.JSON = "json";
  18638. Loader.PREFAB = "prefab";
  18639. Loader.XML = "xml";
  18640. Loader.BUFFER = "arraybuffer";
  18641. Loader.IMAGE = "image";
  18642. Loader.SOUND = "sound";
  18643. Loader.ATLAS = "atlas";
  18644. Loader.FONT = "font";
  18645. Loader.TTF = "ttf";
  18646. Loader.PLF = "plf";
  18647. Loader.PLFB = "plfb";
  18648. Loader.HIERARCHY = "HIERARCHY";
  18649. Loader.MESH = "MESH";
  18650. Loader.MATERIAL = "MATERIAL";
  18651. Loader.TEXTURE2D = "TEXTURE2D";
  18652. Loader.TEXTURECUBE = "TEXTURECUBE";
  18653. Loader.ANIMATIONCLIP = "ANIMATIONCLIP";
  18654. Loader.AVATAR = "AVATAR";
  18655. Loader.TERRAINHEIGHTDATA = "TERRAINHEIGHTDATA";
  18656. Loader.TERRAINRES = "TERRAIN";
  18657. 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" };
  18658. Loader.parserMap = {};
  18659. Loader.maxTimeOut = 100;
  18660. Loader.groupMap = {};
  18661. Loader.loadedMap = {};
  18662. Loader.atlasMap = {};
  18663. Loader.preLoadedMap = {};
  18664. Loader._imgCache = {};
  18665. Loader._loaders = [];
  18666. Loader._isWorking = false;
  18667. Loader._startIndex = 0;
  18668. class AtlasInfoManager {
  18669. static enable(infoFile, callback = null) {
  18670. ILaya.loader.load(infoFile, Handler.create(null, AtlasInfoManager._onInfoLoaded, [callback]), null, Loader.JSON);
  18671. }
  18672. static _onInfoLoaded(callback, data) {
  18673. var tKey;
  18674. var tPrefix;
  18675. var tArr;
  18676. var i, len;
  18677. for (tKey in data) {
  18678. tArr = data[tKey];
  18679. tPrefix = tArr[0];
  18680. tArr = tArr[1];
  18681. len = tArr.length;
  18682. for (i = 0; i < len; i++) {
  18683. AtlasInfoManager._fileLoadDic[tPrefix + tArr[i]] = tKey;
  18684. }
  18685. }
  18686. callback && callback.run();
  18687. }
  18688. static getFileLoadPath(file) {
  18689. return AtlasInfoManager._fileLoadDic[file] || file;
  18690. }
  18691. }
  18692. AtlasInfoManager._fileLoadDic = {};
  18693. class LoaderManager extends EventDispatcher {
  18694. constructor() {
  18695. super();
  18696. this.retryNum = 1;
  18697. this.retryDelay = 0;
  18698. this.maxLoader = 5;
  18699. this._loaders = [];
  18700. this._loaderCount = 0;
  18701. this._resInfos = [];
  18702. this._infoPool = [];
  18703. this._maxPriority = 5;
  18704. this._failRes = {};
  18705. this._statInfo = { count: 1, loaded: 1 };
  18706. for (var i = 0; i < this._maxPriority; i++)
  18707. this._resInfos[i] = [];
  18708. }
  18709. getProgress() {
  18710. return this._statInfo.loaded / this._statInfo.count;
  18711. }
  18712. resetProgress() {
  18713. this._statInfo.count = this._statInfo.loaded = 1;
  18714. }
  18715. create(url, complete = null, progress = null, type = null, constructParams = null, propertyParams = null, priority = 1, cache = true) {
  18716. this._create(url, true, complete, progress, type, constructParams, propertyParams, priority, cache);
  18717. }
  18718. _create(url, mainResou, complete = null, progress = null, type = null, constructParams = null, propertyParams = null, priority = 1, cache = true) {
  18719. if (url instanceof Array) {
  18720. var allScuess = true;
  18721. var items = url;
  18722. var itemCount = items.length;
  18723. var loadedCount = 0;
  18724. if (progress) {
  18725. var progress2 = Handler.create(progress.caller, progress.method, progress.args, false);
  18726. }
  18727. for (var i = 0; i < itemCount; i++) {
  18728. var item = items[i];
  18729. if (typeof (item) == 'string')
  18730. item = items[i] = { url: item };
  18731. item.progress = 0;
  18732. }
  18733. for (i = 0; i < itemCount; i++) {
  18734. item = items[i];
  18735. var progressHandler = progress ? Handler.create(null, function (item, value) {
  18736. item.progress = value;
  18737. var num = 0;
  18738. for (var j = 0; j < itemCount; j++) {
  18739. var item1 = items[j];
  18740. num += item1.progress;
  18741. }
  18742. var v = num / itemCount;
  18743. progress2.runWith(v);
  18744. }, [item], false) : null;
  18745. var completeHandler = (progress || complete) ? Handler.create(null, function (item, content = null) {
  18746. loadedCount++;
  18747. item.progress = 1;
  18748. content || (allScuess = false);
  18749. if (loadedCount === itemCount && complete) {
  18750. complete.runWith(allScuess);
  18751. }
  18752. }, [item]) : null;
  18753. this._createOne(item.url, mainResou, completeHandler, progressHandler, item.type || type, item.constructParams || constructParams, item.propertyParams || propertyParams, item.priority || priority, cache);
  18754. }
  18755. }
  18756. else {
  18757. this._createOne(url, mainResou, complete, progress, type, constructParams, propertyParams, priority, cache);
  18758. }
  18759. }
  18760. _createOne(url, mainResou, complete = null, progress = null, type = null, constructParams = null, propertyParams = null, priority = 1, cache = true) {
  18761. var item = this.getRes(url);
  18762. if (!item) {
  18763. var extension = Utils.getFileExtension(url);
  18764. (type) || (type = LoaderManager.createMap[extension] ? LoaderManager.createMap[extension][0] : null);
  18765. if (!type) {
  18766. this.load(url, complete, progress, type, priority, cache);
  18767. return;
  18768. }
  18769. var parserMap = Loader.parserMap;
  18770. if (!parserMap[type]) {
  18771. this.load(url, complete, progress, type, priority, cache);
  18772. return;
  18773. }
  18774. this._createLoad(url, Handler.create(null, function (createRes) {
  18775. if (createRes) {
  18776. if (!mainResou && createRes instanceof Resource)
  18777. createRes._addReference();
  18778. createRes._setCreateURL(url);
  18779. }
  18780. complete && complete.runWith(createRes);
  18781. ILaya.loader.event(url);
  18782. }), progress, type, constructParams, propertyParams, priority, cache, true);
  18783. }
  18784. else {
  18785. if (!mainResou && item instanceof Resource)
  18786. item._addReference();
  18787. progress && progress.runWith(1);
  18788. complete && complete.runWith(item);
  18789. }
  18790. }
  18791. load(url, complete = null, progress = null, type = null, priority = 1, cache = true, group = null, ignoreCache = false, useWorkerLoader = ILaya.WorkerLoader.enable) {
  18792. if (url instanceof Array)
  18793. return this._loadAssets(url, complete, progress, type, priority, cache, group);
  18794. var content = Loader.getRes(url);
  18795. if (!ignoreCache && content != null) {
  18796. ILaya.systemTimer.frameOnce(1, this, function () {
  18797. progress && progress.runWith(1);
  18798. complete && complete.runWith(content instanceof Array ? [content] : content);
  18799. this._loaderCount || this.event(Event.COMPLETE);
  18800. });
  18801. }
  18802. else {
  18803. var original;
  18804. original = url;
  18805. url = AtlasInfoManager.getFileLoadPath(url);
  18806. if (url != original && type !== "nativeimage") {
  18807. type = Loader.ATLAS;
  18808. }
  18809. else {
  18810. original = null;
  18811. }
  18812. var info = LoaderManager._resMap[url];
  18813. if (!info) {
  18814. info = this._infoPool.length ? this._infoPool.pop() : new ResInfo();
  18815. info.url = url;
  18816. info.type = type;
  18817. info.cache = cache;
  18818. info.group = group;
  18819. info.ignoreCache = ignoreCache;
  18820. info.useWorkerLoader = useWorkerLoader;
  18821. info.originalUrl = original;
  18822. complete && info.on(Event.COMPLETE, complete.caller, complete.method, complete.args);
  18823. progress && info.on(Event.PROGRESS, progress.caller, progress.method, progress.args);
  18824. LoaderManager._resMap[url] = info;
  18825. priority = priority < this._maxPriority ? priority : this._maxPriority - 1;
  18826. this._resInfos[priority].push(info);
  18827. this._statInfo.count++;
  18828. this.event(Event.PROGRESS, this.getProgress());
  18829. this._next();
  18830. }
  18831. else {
  18832. if (complete) {
  18833. if (original) {
  18834. complete && info._createListener(Event.COMPLETE, this, this._resInfoLoaded, [original, complete], false, false);
  18835. }
  18836. else {
  18837. complete && info._createListener(Event.COMPLETE, complete.caller, complete.method, complete.args, false, false);
  18838. }
  18839. }
  18840. progress && info._createListener(Event.PROGRESS, progress.caller, progress.method, progress.args, false, false);
  18841. }
  18842. }
  18843. return this;
  18844. }
  18845. _resInfoLoaded(original, complete) {
  18846. complete.runWith(Loader.getRes(original));
  18847. }
  18848. _createLoad(url, complete = null, progress = null, type = null, constructParams = null, propertyParams = null, priority = 1, cache = true, ignoreCache = false) {
  18849. if (url instanceof Array)
  18850. return this._loadAssets(url, complete, progress, type, priority, cache);
  18851. var content = Loader.getRes(url);
  18852. if (content != null) {
  18853. ILaya.systemTimer.frameOnce(1, this, function () {
  18854. progress && progress.runWith(1);
  18855. complete && complete.runWith(content);
  18856. this._loaderCount || this.event(Event.COMPLETE);
  18857. });
  18858. }
  18859. else {
  18860. var info = LoaderManager._resMap[url];
  18861. if (!info) {
  18862. info = this._infoPool.length ? this._infoPool.pop() : new ResInfo();
  18863. info.url = url;
  18864. info.type = type;
  18865. info.cache = false;
  18866. info.ignoreCache = ignoreCache;
  18867. info.originalUrl = null;
  18868. info.group = null;
  18869. info.createCache = cache;
  18870. info.createConstructParams = constructParams;
  18871. info.createPropertyParams = propertyParams;
  18872. complete && info.on(Event.COMPLETE, complete.caller, complete.method, complete.args);
  18873. progress && info.on(Event.PROGRESS, progress.caller, progress.method, progress.args);
  18874. LoaderManager._resMap[url] = info;
  18875. priority = priority < this._maxPriority ? priority : this._maxPriority - 1;
  18876. this._resInfos[priority].push(info);
  18877. this._statInfo.count++;
  18878. this.event(Event.PROGRESS, this.getProgress());
  18879. this._next();
  18880. }
  18881. else {
  18882. complete && info._createListener(Event.COMPLETE, complete.caller, complete.method, complete.args, false, false);
  18883. progress && info._createListener(Event.PROGRESS, progress.caller, progress.method, progress.args, false, false);
  18884. }
  18885. }
  18886. return this;
  18887. }
  18888. _next() {
  18889. if (this._loaderCount >= this.maxLoader)
  18890. return;
  18891. for (var i = 0; i < this._maxPriority; i++) {
  18892. var infos = this._resInfos[i];
  18893. while (infos.length > 0) {
  18894. var info = infos.shift();
  18895. if (info)
  18896. return this._doLoad(info);
  18897. }
  18898. }
  18899. this._loaderCount || this.event(Event.COMPLETE);
  18900. }
  18901. _doLoad(resInfo) {
  18902. this._loaderCount++;
  18903. var loader = this._loaders.length ? this._loaders.pop() : new Loader();
  18904. loader.on(Event.COMPLETE, null, onLoaded);
  18905. loader.on(Event.PROGRESS, null, function (num) {
  18906. resInfo.event(Event.PROGRESS, num);
  18907. });
  18908. loader.on(Event.ERROR, null, function (msg) {
  18909. onLoaded(null);
  18910. });
  18911. var _me = this;
  18912. function onLoaded(data = null) {
  18913. loader.offAll();
  18914. loader._data = null;
  18915. loader._customParse = false;
  18916. _me._loaders.push(loader);
  18917. _me._endLoad(resInfo, data instanceof Array ? [data] : data);
  18918. _me._loaderCount--;
  18919. _me._next();
  18920. }
  18921. loader._constructParams = resInfo.createConstructParams;
  18922. loader._propertyParams = resInfo.createPropertyParams;
  18923. loader._createCache = resInfo.createCache;
  18924. loader.load(resInfo.url, resInfo.type, resInfo.cache, resInfo.group, resInfo.ignoreCache, resInfo.useWorkerLoader);
  18925. }
  18926. _endLoad(resInfo, content) {
  18927. var url = resInfo.url;
  18928. if (content == null) {
  18929. var errorCount = this._failRes[url] || 0;
  18930. if (errorCount < this.retryNum) {
  18931. console.warn("[warn]Retry to load:", url);
  18932. this._failRes[url] = errorCount + 1;
  18933. ILaya.systemTimer.once(this.retryDelay, this, this._addReTry, [resInfo], false);
  18934. return;
  18935. }
  18936. else {
  18937. Loader.clearRes(url);
  18938. console.warn("[error]Failed to load:", url);
  18939. this.event(Event.ERROR, url);
  18940. }
  18941. }
  18942. if (this._failRes[url])
  18943. this._failRes[url] = 0;
  18944. delete LoaderManager._resMap[url];
  18945. if (resInfo.originalUrl) {
  18946. content = Loader.getRes(resInfo.originalUrl);
  18947. }
  18948. resInfo.event(Event.COMPLETE, content);
  18949. resInfo.offAll();
  18950. this._infoPool.push(resInfo);
  18951. this._statInfo.loaded++;
  18952. this.event(Event.PROGRESS, this.getProgress());
  18953. }
  18954. _addReTry(resInfo) {
  18955. this._resInfos[this._maxPriority - 1].push(resInfo);
  18956. this._next();
  18957. }
  18958. clearRes(url) {
  18959. Loader.clearRes(url);
  18960. }
  18961. clearTextureRes(url) {
  18962. Loader.clearTextureRes(url);
  18963. }
  18964. getRes(url) {
  18965. return Loader.getRes(url);
  18966. }
  18967. cacheRes(url, data) {
  18968. Loader.cacheRes(url, data);
  18969. }
  18970. setGroup(url, group) {
  18971. Loader.setGroup(url, group);
  18972. }
  18973. clearResByGroup(group) {
  18974. Loader.clearResByGroup(group);
  18975. }
  18976. static cacheRes(url, data) {
  18977. Loader.cacheRes(url, data);
  18978. }
  18979. clearUnLoaded() {
  18980. for (var i = 0; i < this._maxPriority; i++) {
  18981. var infos = this._resInfos[i];
  18982. for (var j = infos.length - 1; j > -1; j--) {
  18983. var info = infos[j];
  18984. if (info) {
  18985. info.offAll();
  18986. this._infoPool.push(info);
  18987. }
  18988. }
  18989. infos.length = 0;
  18990. }
  18991. this._loaderCount = 0;
  18992. LoaderManager._resMap = {};
  18993. }
  18994. cancelLoadByUrls(urls) {
  18995. if (!urls)
  18996. return;
  18997. for (var i = 0, n = urls.length; i < n; i++) {
  18998. this.cancelLoadByUrl(urls[i]);
  18999. }
  19000. }
  19001. cancelLoadByUrl(url) {
  19002. for (var i = 0; i < this._maxPriority; i++) {
  19003. var infos = this._resInfos[i];
  19004. for (var j = infos.length - 1; j > -1; j--) {
  19005. var info = infos[j];
  19006. if (info && info.url === url) {
  19007. infos[j] = null;
  19008. info.offAll();
  19009. this._infoPool.push(info);
  19010. }
  19011. }
  19012. }
  19013. if (LoaderManager._resMap[url])
  19014. delete LoaderManager._resMap[url];
  19015. }
  19016. _loadAssets(arr, complete = null, progress = null, type = null, priority = 1, cache = true, group = null) {
  19017. var itemCount = arr.length;
  19018. var loadedCount = 0;
  19019. var totalSize = 0;
  19020. var items = [];
  19021. var success = true;
  19022. for (var i = 0; i < itemCount; i++) {
  19023. var item = arr[i];
  19024. if (typeof (item) == 'string')
  19025. item = { url: item, type: type, size: 1, priority: priority };
  19026. if (!item.size)
  19027. item.size = 1;
  19028. item.progress = 0;
  19029. totalSize += item.size;
  19030. items.push(item);
  19031. var progressHandler = progress ? Handler.create(null, loadProgress, [item], false) : null;
  19032. var completeHandler = (complete || progress) ? Handler.create(null, loadComplete, [item]) : null;
  19033. this.load(item.url, completeHandler, progressHandler, item.type, item.priority || 1, cache, item.group || group, false, item.useWorkerLoader);
  19034. }
  19035. function loadComplete(item, content = null) {
  19036. loadedCount++;
  19037. item.progress = 1;
  19038. if (!content)
  19039. success = false;
  19040. if (loadedCount === itemCount && complete) {
  19041. complete.runWith(success);
  19042. }
  19043. }
  19044. function loadProgress(item, value) {
  19045. if (progress != null) {
  19046. item.progress = value;
  19047. var num = 0;
  19048. for (var j = 0; j < items.length; j++) {
  19049. var item1 = items[j];
  19050. num += item1.size * item1.progress;
  19051. }
  19052. var v = num / totalSize;
  19053. progress.runWith(v);
  19054. }
  19055. }
  19056. return this;
  19057. }
  19058. decodeBitmaps(urls) {
  19059. var i, len = urls.length;
  19060. var ctx;
  19061. ctx = ILaya.Render._context;
  19062. for (i = 0; i < len; i++) {
  19063. var atlas;
  19064. atlas = Loader.getAtlas(urls[i]);
  19065. if (atlas) {
  19066. this._decodeTexture(atlas[0], ctx);
  19067. }
  19068. else {
  19069. var tex;
  19070. tex = this.getRes(urls[i]);
  19071. if (tex && tex instanceof Texture) {
  19072. this._decodeTexture(tex, ctx);
  19073. }
  19074. }
  19075. }
  19076. }
  19077. _decodeTexture(tex, ctx) {
  19078. var bitmap = tex.bitmap;
  19079. if (!tex || !bitmap)
  19080. return;
  19081. var tImg = bitmap.source || bitmap.image;
  19082. if (!tImg)
  19083. return;
  19084. if (tImg instanceof HTMLImageElement) {
  19085. ctx.drawImage(tImg, 0, 0, 1, 1);
  19086. var info = ctx.getImageData(0, 0, 1, 1);
  19087. }
  19088. }
  19089. }
  19090. LoaderManager._resMap = {};
  19091. LoaderManager.createMap = { atlas: [null, Loader.ATLAS] };
  19092. class ResInfo extends EventDispatcher {
  19093. }
  19094. class LocalStorage {
  19095. static __init__() {
  19096. if (!LocalStorage._baseClass) {
  19097. LocalStorage._baseClass = Storage;
  19098. Storage.init();
  19099. }
  19100. LocalStorage.items = LocalStorage._baseClass.items;
  19101. LocalStorage.support = LocalStorage._baseClass.support;
  19102. return LocalStorage.support;
  19103. }
  19104. static setItem(key, value) {
  19105. LocalStorage._baseClass.setItem(key, value);
  19106. }
  19107. static getItem(key) {
  19108. return LocalStorage._baseClass.getItem(key);
  19109. }
  19110. static setJSON(key, value) {
  19111. LocalStorage._baseClass.setJSON(key, value);
  19112. }
  19113. static getJSON(key) {
  19114. return LocalStorage._baseClass.getJSON(key);
  19115. }
  19116. static removeItem(key) {
  19117. LocalStorage._baseClass.removeItem(key);
  19118. }
  19119. static clear() {
  19120. LocalStorage._baseClass.clear();
  19121. }
  19122. }
  19123. LocalStorage.support = false;
  19124. class Storage {
  19125. static init() {
  19126. try {
  19127. Storage.support = true;
  19128. Storage.items = window.localStorage;
  19129. Storage.setItem('laya', '1');
  19130. Storage.removeItem('laya');
  19131. }
  19132. catch (e) {
  19133. Storage.support = false;
  19134. }
  19135. if (!Storage.support)
  19136. console.log('LocalStorage is not supprot or browser is private mode.');
  19137. }
  19138. static setItem(key, value) {
  19139. try {
  19140. Storage.support && Storage.items.setItem(key, value);
  19141. }
  19142. catch (e) {
  19143. console.warn("set localStorage failed", e);
  19144. }
  19145. }
  19146. static getItem(key) {
  19147. return Storage.support ? Storage.items.getItem(key) : null;
  19148. }
  19149. static setJSON(key, value) {
  19150. try {
  19151. Storage.support && Storage.items.setItem(key, JSON.stringify(value));
  19152. }
  19153. catch (e) {
  19154. console.warn("set localStorage failed", e);
  19155. }
  19156. }
  19157. static getJSON(key) {
  19158. return JSON.parse(Storage.support ? Storage.items.getItem(key) : null);
  19159. }
  19160. static removeItem(key) {
  19161. Storage.support && Storage.items.removeItem(key);
  19162. }
  19163. static clear() {
  19164. Storage.support && Storage.items.clear();
  19165. }
  19166. }
  19167. Storage.support = false;
  19168. class TTFLoader {
  19169. load(fontPath) {
  19170. this._url = fontPath;
  19171. var tArr = fontPath.split(".ttf")[0].split("/");
  19172. this.fontName = tArr[tArr.length - 1];
  19173. if (ILaya.Render.isConchApp) {
  19174. this._loadConch();
  19175. }
  19176. else if (window.FontFace) {
  19177. this._loadWithFontFace();
  19178. }
  19179. else {
  19180. this._loadWithCSS();
  19181. }
  19182. }
  19183. _loadConch() {
  19184. this._http = new HttpRequest();
  19185. this._http.on(Event.ERROR, this, this._onErr);
  19186. this._http.on(Event.COMPLETE, this, this._onHttpLoaded);
  19187. this._http.send(this._url, null, "get", Loader.BUFFER);
  19188. }
  19189. _onHttpLoaded(data = null) {
  19190. window["conchTextCanvas"].setFontFaceFromBuffer(this.fontName, data);
  19191. this._clearHttp();
  19192. this._complete();
  19193. }
  19194. _clearHttp() {
  19195. if (this._http) {
  19196. this._http.off(Event.ERROR, this, this._onErr);
  19197. this._http.off(Event.COMPLETE, this, this._onHttpLoaded);
  19198. this._http = null;
  19199. }
  19200. }
  19201. _onErr() {
  19202. this._clearHttp();
  19203. if (this.err) {
  19204. this.err.runWith("fail:" + this._url);
  19205. this.err = null;
  19206. }
  19207. }
  19208. _complete() {
  19209. ILaya.systemTimer.clear(this, this._complete);
  19210. ILaya.systemTimer.clear(this, this._checkComplete);
  19211. if (this._div && this._div.parentNode) {
  19212. this._div.parentNode.removeChild(this._div);
  19213. this._div = null;
  19214. }
  19215. if (this.complete) {
  19216. this.complete.runWith(this);
  19217. this.complete = null;
  19218. }
  19219. }
  19220. _checkComplete() {
  19221. if (ILaya.Browser.measureText(TTFLoader._testString, this._fontTxt).width != this._txtWidth) {
  19222. this._complete();
  19223. }
  19224. }
  19225. _loadWithFontFace() {
  19226. var fontFace = new window.FontFace(this.fontName, "url('" + this._url + "')");
  19227. document.fonts.add(fontFace);
  19228. var self = this;
  19229. fontFace.loaded.then((function () {
  19230. self._complete();
  19231. }));
  19232. fontFace.load();
  19233. }
  19234. _createDiv() {
  19235. this._div = Browser.createElement("div");
  19236. this._div.innerHTML = "laya";
  19237. var _style = this._div.style;
  19238. _style.fontFamily = this.fontName;
  19239. _style.position = "absolute";
  19240. _style.left = "-100px";
  19241. _style.top = "-100px";
  19242. document.body.appendChild(this._div);
  19243. }
  19244. _loadWithCSS() {
  19245. var fontStyle = Browser.createElement("style");
  19246. fontStyle.type = "text/css";
  19247. document.body.appendChild(fontStyle);
  19248. fontStyle.textContent = "@font-face { font-family:'" + this.fontName + "'; src:url('" + this._url + "');}";
  19249. this._fontTxt = "40px " + this.fontName;
  19250. this._txtWidth = Browser.measureText(TTFLoader._testString, this._fontTxt).width;
  19251. var self = this;
  19252. fontStyle.onload = function () {
  19253. ILaya.systemTimer.once(10000, self, this._complete);
  19254. };
  19255. ILaya.systemTimer.loop(20, this, this._checkComplete);
  19256. this._createDiv();
  19257. }
  19258. }
  19259. TTFLoader._testString = "LayaTTFFont";
  19260. class Ease {
  19261. static linearNone(t, b, c, d) {
  19262. return c * t / d + b;
  19263. }
  19264. static linearIn(t, b, c, d) {
  19265. return c * t / d + b;
  19266. }
  19267. static linearInOut(t, b, c, d) {
  19268. return c * t / d + b;
  19269. }
  19270. static linearOut(t, b, c, d) {
  19271. return c * t / d + b;
  19272. }
  19273. static bounceIn(t, b, c, d) {
  19274. return c - Ease.bounceOut(d - t, 0, c, d) + b;
  19275. }
  19276. static bounceInOut(t, b, c, d) {
  19277. if (t < d * 0.5)
  19278. return Ease.bounceIn(t * 2, 0, c, d) * .5 + b;
  19279. else
  19280. return Ease.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
  19281. }
  19282. static bounceOut(t, b, c, d) {
  19283. if ((t /= d) < (1 / 2.75))
  19284. return c * (7.5625 * t * t) + b;
  19285. else if (t < (2 / 2.75))
  19286. return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
  19287. else if (t < (2.5 / 2.75))
  19288. return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
  19289. else
  19290. return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
  19291. }
  19292. static backIn(t, b, c, d, s = 1.70158) {
  19293. return c * (t /= d) * t * ((s + 1) * t - s) + b;
  19294. }
  19295. static backInOut(t, b, c, d, s = 1.70158) {
  19296. if ((t /= d * 0.5) < 1)
  19297. return c * 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
  19298. return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
  19299. }
  19300. static backOut(t, b, c, d, s = 1.70158) {
  19301. return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
  19302. }
  19303. static elasticIn(t, b, c, d, a = 0, p = 0) {
  19304. var s;
  19305. if (t == 0)
  19306. return b;
  19307. if ((t /= d) == 1)
  19308. return b + c;
  19309. if (!p)
  19310. p = d * .3;
  19311. if (!a || (c > 0 && a < c) || (c < 0 && a < -c)) {
  19312. a = c;
  19313. s = p / 4;
  19314. }
  19315. else
  19316. s = p / Ease.PI2 * Math.asin(c / a);
  19317. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * Ease.PI2 / p)) + b;
  19318. }
  19319. static elasticInOut(t, b, c, d, a = 0, p = 0) {
  19320. var s;
  19321. if (t == 0)
  19322. return b;
  19323. if ((t /= d * 0.5) == 2)
  19324. return b + c;
  19325. if (!p)
  19326. p = d * (.3 * 1.5);
  19327. if (!a || (c > 0 && a < c) || (c < 0 && a < -c)) {
  19328. a = c;
  19329. s = p / 4;
  19330. }
  19331. else
  19332. s = p / Ease.PI2 * Math.asin(c / a);
  19333. if (t < 1)
  19334. return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * Ease.PI2 / p)) + b;
  19335. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * Ease.PI2 / p) * .5 + c + b;
  19336. }
  19337. static elasticOut(t, b, c, d, a = 0, p = 0) {
  19338. var s;
  19339. if (t == 0)
  19340. return b;
  19341. if ((t /= d) == 1)
  19342. return b + c;
  19343. if (!p)
  19344. p = d * .3;
  19345. if (!a || (c > 0 && a < c) || (c < 0 && a < -c)) {
  19346. a = c;
  19347. s = p / 4;
  19348. }
  19349. else
  19350. s = p / Ease.PI2 * Math.asin(c / a);
  19351. return (a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * Ease.PI2 / p) + c + b);
  19352. }
  19353. static strongIn(t, b, c, d) {
  19354. return c * (t /= d) * t * t * t * t + b;
  19355. }
  19356. static strongInOut(t, b, c, d) {
  19357. if ((t /= d * 0.5) < 1)
  19358. return c * 0.5 * t * t * t * t * t + b;
  19359. return c * 0.5 * ((t -= 2) * t * t * t * t + 2) + b;
  19360. }
  19361. static strongOut(t, b, c, d) {
  19362. return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
  19363. }
  19364. static sineInOut(t, b, c, d) {
  19365. return -c * 0.5 * (Math.cos(Math.PI * t / d) - 1) + b;
  19366. }
  19367. static sineIn(t, b, c, d) {
  19368. return -c * Math.cos(t / d * Ease.HALF_PI) + c + b;
  19369. }
  19370. static sineOut(t, b, c, d) {
  19371. return c * Math.sin(t / d * Ease.HALF_PI) + b;
  19372. }
  19373. static quintIn(t, b, c, d) {
  19374. return c * (t /= d) * t * t * t * t + b;
  19375. }
  19376. static quintInOut(t, b, c, d) {
  19377. if ((t /= d * 0.5) < 1)
  19378. return c * 0.5 * t * t * t * t * t + b;
  19379. return c * 0.5 * ((t -= 2) * t * t * t * t + 2) + b;
  19380. }
  19381. static quintOut(t, b, c, d) {
  19382. return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
  19383. }
  19384. static quartIn(t, b, c, d) {
  19385. return c * (t /= d) * t * t * t + b;
  19386. }
  19387. static quartInOut(t, b, c, d) {
  19388. if ((t /= d * 0.5) < 1)
  19389. return c * 0.5 * t * t * t * t + b;
  19390. return -c * 0.5 * ((t -= 2) * t * t * t - 2) + b;
  19391. }
  19392. static quartOut(t, b, c, d) {
  19393. return -c * ((t = t / d - 1) * t * t * t - 1) + b;
  19394. }
  19395. static cubicIn(t, b, c, d) {
  19396. return c * (t /= d) * t * t + b;
  19397. }
  19398. static cubicInOut(t, b, c, d) {
  19399. if ((t /= d * 0.5) < 1)
  19400. return c * 0.5 * t * t * t + b;
  19401. return c * 0.5 * ((t -= 2) * t * t + 2) + b;
  19402. }
  19403. static cubicOut(t, b, c, d) {
  19404. return c * ((t = t / d - 1) * t * t + 1) + b;
  19405. }
  19406. static quadIn(t, b, c, d) {
  19407. return c * (t /= d) * t + b;
  19408. }
  19409. static quadInOut(t, b, c, d) {
  19410. if ((t /= d * 0.5) < 1)
  19411. return c * 0.5 * t * t + b;
  19412. return -c * 0.5 * ((--t) * (t - 2) - 1) + b;
  19413. }
  19414. static quadOut(t, b, c, d) {
  19415. return -c * (t /= d) * (t - 2) + b;
  19416. }
  19417. static expoIn(t, b, c, d) {
  19418. return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b - c * 0.001;
  19419. }
  19420. static expoInOut(t, b, c, d) {
  19421. if (t == 0)
  19422. return b;
  19423. if (t == d)
  19424. return b + c;
  19425. if ((t /= d * 0.5) < 1)
  19426. return c * 0.5 * Math.pow(2, 10 * (t - 1)) + b;
  19427. return c * 0.5 * (-Math.pow(2, -10 * --t) + 2) + b;
  19428. }
  19429. static expoOut(t, b, c, d) {
  19430. return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
  19431. }
  19432. static circIn(t, b, c, d) {
  19433. return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
  19434. }
  19435. static circInOut(t, b, c, d) {
  19436. if ((t /= d * 0.5) < 1)
  19437. return -c * 0.5 * (Math.sqrt(1 - t * t) - 1) + b;
  19438. return c * 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
  19439. }
  19440. static circOut(t, b, c, d) {
  19441. return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
  19442. }
  19443. }
  19444. Ease.HALF_PI = Math.PI * 0.5;
  19445. Ease.PI2 = Math.PI * 2;
  19446. class Tween {
  19447. constructor() {
  19448. this.gid = 0;
  19449. this.repeat = 1;
  19450. this._count = 0;
  19451. }
  19452. static to(target, props, duration, ease = null, complete = null, delay = 0, coverBefore = false, autoRecover = true) {
  19453. return Pool.getItemByClass("tween", Tween)._create(target, props, duration, ease, complete, delay, coverBefore, true, autoRecover, true);
  19454. }
  19455. static from(target, props, duration, ease = null, complete = null, delay = 0, coverBefore = false, autoRecover = true) {
  19456. return Pool.getItemByClass("tween", Tween)._create(target, props, duration, ease, complete, delay, coverBefore, false, autoRecover, true);
  19457. }
  19458. to(target, props, duration, ease = null, complete = null, delay = 0, coverBefore = false) {
  19459. return this._create(target, props, duration, ease, complete, delay, coverBefore, true, false, true);
  19460. }
  19461. from(target, props, duration, ease = null, complete = null, delay = 0, coverBefore = false) {
  19462. return this._create(target, props, duration, ease, complete, delay, coverBefore, false, false, true);
  19463. }
  19464. _create(target, props, duration, ease, complete, delay, coverBefore, isTo, usePool, runNow) {
  19465. if (!target)
  19466. throw new Error("Tween:target is null");
  19467. this._target = target;
  19468. this._duration = duration;
  19469. this._ease = ease || props.ease || Tween.easeNone;
  19470. this._complete = complete || props.complete;
  19471. this._delay = delay;
  19472. this._props = [];
  19473. this._usedTimer = 0;
  19474. this._startTimer = Browser.now();
  19475. this._usedPool = usePool;
  19476. this._delayParam = null;
  19477. this.update = props.update;
  19478. var gid = (target.$_GID || (target.$_GID = Utils.getGID()));
  19479. if (!Tween.tweenMap[gid]) {
  19480. Tween.tweenMap[gid] = [this];
  19481. }
  19482. else {
  19483. if (coverBefore)
  19484. Tween.clearTween(target);
  19485. Tween.tweenMap[gid].push(this);
  19486. }
  19487. if (runNow) {
  19488. if (delay <= 0)
  19489. this.firstStart(target, props, isTo);
  19490. else {
  19491. this._delayParam = [target, props, isTo];
  19492. ILaya.timer.once(delay, this, this.firstStart, this._delayParam);
  19493. }
  19494. }
  19495. else {
  19496. this._initProps(target, props, isTo);
  19497. }
  19498. return this;
  19499. }
  19500. firstStart(target, props, isTo) {
  19501. this._delayParam = null;
  19502. if (target.destroyed) {
  19503. this.clear();
  19504. return;
  19505. }
  19506. this._initProps(target, props, isTo);
  19507. this._beginLoop();
  19508. }
  19509. _initProps(target, props, isTo) {
  19510. for (var p in props) {
  19511. if (typeof (target[p]) == 'number') {
  19512. var start = isTo ? target[p] : props[p];
  19513. var end = isTo ? props[p] : target[p];
  19514. this._props.push([p, start, end - start]);
  19515. if (!isTo)
  19516. target[p] = start;
  19517. }
  19518. }
  19519. }
  19520. _beginLoop() {
  19521. ILaya.timer.frameLoop(1, this, this._doEase);
  19522. }
  19523. _doEase() {
  19524. this._updateEase(Browser.now());
  19525. }
  19526. _updateEase(time) {
  19527. var target = this._target;
  19528. if (!target)
  19529. return;
  19530. if (target.destroyed)
  19531. return Tween.clearTween(target);
  19532. var usedTimer = this._usedTimer = time - this._startTimer - this._delay;
  19533. if (usedTimer < 0)
  19534. return;
  19535. if (usedTimer >= this._duration)
  19536. return this.complete();
  19537. var ratio = usedTimer > 0 ? this._ease(usedTimer, 0, 1, this._duration) : 0;
  19538. var props = this._props;
  19539. for (var i = 0, n = props.length; i < n; i++) {
  19540. var prop = props[i];
  19541. target[prop[0]] = prop[1] + (ratio * prop[2]);
  19542. }
  19543. if (this.update)
  19544. this.update.run();
  19545. }
  19546. set progress(v) {
  19547. var uTime = v * this._duration;
  19548. this._startTimer = Browser.now() - this._delay - uTime;
  19549. }
  19550. complete() {
  19551. if (!this._target)
  19552. return;
  19553. ILaya.timer.runTimer(this, this.firstStart);
  19554. var target = this._target;
  19555. var props = this._props;
  19556. var handler = this._complete;
  19557. for (var i = 0, n = props.length; i < n; i++) {
  19558. var prop = props[i];
  19559. target[prop[0]] = prop[1] + prop[2];
  19560. }
  19561. if (this.update)
  19562. this.update.run();
  19563. this._count++;
  19564. if (this.repeat != 0 && this._count >= this.repeat) {
  19565. this.clear();
  19566. handler && handler.run();
  19567. }
  19568. else {
  19569. this.restart();
  19570. }
  19571. }
  19572. pause() {
  19573. ILaya.timer.clear(this, this._beginLoop);
  19574. ILaya.timer.clear(this, this._doEase);
  19575. ILaya.timer.clear(this, this.firstStart);
  19576. var time = Browser.now();
  19577. var dTime;
  19578. dTime = time - this._startTimer - this._delay;
  19579. if (dTime < 0) {
  19580. this._usedTimer = dTime;
  19581. }
  19582. }
  19583. setStartTime(startTime) {
  19584. this._startTimer = startTime;
  19585. }
  19586. static clearAll(target) {
  19587. if (!target || !target.$_GID)
  19588. return;
  19589. var tweens = Tween.tweenMap[target.$_GID];
  19590. if (tweens) {
  19591. for (var i = 0, n = tweens.length; i < n; i++) {
  19592. tweens[i]._clear();
  19593. }
  19594. tweens.length = 0;
  19595. }
  19596. }
  19597. static clear(tween) {
  19598. tween.clear();
  19599. }
  19600. static clearTween(target) {
  19601. Tween.clearAll(target);
  19602. }
  19603. clear() {
  19604. if (this._target) {
  19605. this._remove();
  19606. this._clear();
  19607. }
  19608. }
  19609. _clear() {
  19610. this.pause();
  19611. ILaya.timer.clear(this, this.firstStart);
  19612. this._complete = null;
  19613. this._target = null;
  19614. this._ease = null;
  19615. this._props = null;
  19616. this._delayParam = null;
  19617. if (this._usedPool) {
  19618. this.update = null;
  19619. Pool.recover("tween", this);
  19620. }
  19621. }
  19622. recover() {
  19623. this._usedPool = true;
  19624. this._clear();
  19625. }
  19626. _remove() {
  19627. var tweens = Tween.tweenMap[this._target.$_GID];
  19628. if (tweens) {
  19629. for (var i = 0, n = tweens.length; i < n; i++) {
  19630. if (tweens[i] === this) {
  19631. tweens.splice(i, 1);
  19632. break;
  19633. }
  19634. }
  19635. }
  19636. }
  19637. restart() {
  19638. this.pause();
  19639. this._usedTimer = 0;
  19640. this._startTimer = Browser.now();
  19641. if (this._delayParam) {
  19642. ILaya.timer.once(this._delay, this, this.firstStart, this._delayParam);
  19643. return;
  19644. }
  19645. var props = this._props;
  19646. for (var i = 0, n = props.length; i < n; i++) {
  19647. var prop = props[i];
  19648. this._target[prop[0]] = prop[1];
  19649. }
  19650. ILaya.timer.once(this._delay, this, this._beginLoop);
  19651. }
  19652. resume() {
  19653. if (this._usedTimer >= this._duration)
  19654. return;
  19655. this._startTimer = Browser.now() - this._usedTimer - this._delay;
  19656. if (this._delayParam) {
  19657. if (this._usedTimer < 0) {
  19658. ILaya.timer.once(-this._usedTimer, this, this.firstStart, this._delayParam);
  19659. }
  19660. else {
  19661. this.firstStart.apply(this, this._delayParam);
  19662. }
  19663. }
  19664. else {
  19665. this._beginLoop();
  19666. }
  19667. }
  19668. static easeNone(t, b, c, d) {
  19669. return c * t / d + b;
  19670. }
  19671. }
  19672. Tween.tweenMap = [];
  19673. class Dragging {
  19674. constructor() {
  19675. this.ratio = 0.92;
  19676. this.maxOffset = 60;
  19677. this._dragging = false;
  19678. this._clickOnly = true;
  19679. }
  19680. start(target, area, hasInertia, elasticDistance, elasticBackTime, data, disableMouseEvent, ratio = 0.92) {
  19681. this.clearTimer();
  19682. this.target = target;
  19683. this.area = area;
  19684. this.hasInertia = hasInertia;
  19685. this.elasticDistance = area ? elasticDistance : 0;
  19686. this.elasticBackTime = elasticBackTime;
  19687. this.data = data;
  19688. this._disableMouseEvent = disableMouseEvent;
  19689. this.ratio = ratio;
  19690. this._parent = target.parent;
  19691. this._clickOnly = true;
  19692. this._dragging = true;
  19693. this._elasticRateX = this._elasticRateY = 1;
  19694. this._lastX = this._parent.mouseX;
  19695. this._lastY = this._parent.mouseY;
  19696. ILaya.stage.on(Event.MOUSE_UP, this, this.onStageMouseUp);
  19697. ILaya.stage.on(Event.MOUSE_OUT, this, this.onStageMouseUp);
  19698. ILaya.systemTimer.frameLoop(1, this, this.loop);
  19699. }
  19700. clearTimer() {
  19701. ILaya.systemTimer.clear(this, this.loop);
  19702. ILaya.systemTimer.clear(this, this.tweenMove);
  19703. if (this._tween) {
  19704. this._tween.recover();
  19705. this._tween = null;
  19706. }
  19707. }
  19708. stop() {
  19709. if (this._dragging) {
  19710. MouseManager.instance.disableMouseEvent = false;
  19711. ILaya.stage.off(Event.MOUSE_UP, this, this.onStageMouseUp);
  19712. ILaya.stage.off(Event.MOUSE_OUT, this, this.onStageMouseUp);
  19713. this._dragging = false;
  19714. this.target && this.area && this.backToArea();
  19715. this.clear();
  19716. }
  19717. }
  19718. loop() {
  19719. var point = this._parent.getMousePoint();
  19720. var mouseX = point.x;
  19721. var mouseY = point.y;
  19722. var offsetX = mouseX - this._lastX;
  19723. var offsetY = mouseY - this._lastY;
  19724. if (this._clickOnly) {
  19725. if (Math.abs(offsetX * ILaya.stage._canvasTransform.getScaleX()) > 1 || Math.abs(offsetY * ILaya.stage._canvasTransform.getScaleY()) > 1) {
  19726. this._clickOnly = false;
  19727. this._offsets || (this._offsets = []);
  19728. this._offsets.length = 0;
  19729. this.target.event(Event.DRAG_START, this.data);
  19730. MouseManager.instance.disableMouseEvent = this._disableMouseEvent;
  19731. }
  19732. else
  19733. return;
  19734. }
  19735. else {
  19736. this._offsets.push(offsetX, offsetY);
  19737. }
  19738. if (offsetX === 0 && offsetY === 0)
  19739. return;
  19740. this._lastX = mouseX;
  19741. this._lastY = mouseY;
  19742. this.target.x += offsetX * this._elasticRateX;
  19743. this.target.y += offsetY * this._elasticRateY;
  19744. this.area && this.checkArea();
  19745. this.target.event(Event.DRAG_MOVE, this.data);
  19746. }
  19747. checkArea() {
  19748. if (this.elasticDistance <= 0) {
  19749. this.backToArea();
  19750. }
  19751. else {
  19752. if (this.target._x < this.area.x) {
  19753. var offsetX = this.area.x - this.target._x;
  19754. }
  19755. else if (this.target._x > this.area.x + this.area.width) {
  19756. offsetX = this.target._x - this.area.x - this.area.width;
  19757. }
  19758. else {
  19759. offsetX = 0;
  19760. }
  19761. this._elasticRateX = Math.max(0, 1 - (offsetX / this.elasticDistance));
  19762. if (this.target._y < this.area.y) {
  19763. var offsetY = this.area.y - this.target.y;
  19764. }
  19765. else if (this.target._y > this.area.y + this.area.height) {
  19766. offsetY = this.target._y - this.area.y - this.area.height;
  19767. }
  19768. else {
  19769. offsetY = 0;
  19770. }
  19771. this._elasticRateY = Math.max(0, 1 - (offsetY / this.elasticDistance));
  19772. }
  19773. }
  19774. backToArea() {
  19775. this.target.x = Math.min(Math.max(this.target._x, this.area.x), this.area.x + this.area.width);
  19776. this.target.y = Math.min(Math.max(this.target._y, this.area.y), this.area.y + this.area.height);
  19777. }
  19778. onStageMouseUp(e) {
  19779. MouseManager.instance.disableMouseEvent = false;
  19780. ILaya.stage.off(Event.MOUSE_UP, this, this.onStageMouseUp);
  19781. ILaya.stage.off(Event.MOUSE_OUT, this, this.onStageMouseUp);
  19782. ILaya.systemTimer.clear(this, this.loop);
  19783. if (this._clickOnly || !this.target)
  19784. return;
  19785. if (this.hasInertia) {
  19786. if (this._offsets.length < 1) {
  19787. this._offsets.push(this._parent.mouseX - this._lastX, this._parent.mouseY - this._lastY);
  19788. }
  19789. this._offsetX = this._offsetY = 0;
  19790. var len = this._offsets.length;
  19791. var n = Math.min(len, 6);
  19792. var m = this._offsets.length - n;
  19793. for (var i = len - 1; i > m; i--) {
  19794. this._offsetY += this._offsets[i--];
  19795. this._offsetX += this._offsets[i];
  19796. }
  19797. this._offsetX = this._offsetX / n * 2;
  19798. this._offsetY = this._offsetY / n * 2;
  19799. if (Math.abs(this._offsetX) > this.maxOffset)
  19800. this._offsetX = this._offsetX > 0 ? this.maxOffset : -this.maxOffset;
  19801. if (Math.abs(this._offsetY) > this.maxOffset)
  19802. this._offsetY = this._offsetY > 0 ? this.maxOffset : -this.maxOffset;
  19803. ILaya.systemTimer.frameLoop(1, this, this.tweenMove);
  19804. }
  19805. else if (this.elasticDistance > 0) {
  19806. this.checkElastic();
  19807. }
  19808. else {
  19809. this.clear();
  19810. }
  19811. }
  19812. checkElastic() {
  19813. var tx = NaN;
  19814. var ty = NaN;
  19815. if (this.target.x < this.area.x)
  19816. tx = this.area.x;
  19817. else if (this.target._x > this.area.x + this.area.width)
  19818. tx = this.area.x + this.area.width;
  19819. if (this.target.y < this.area.y)
  19820. ty = this.area.y;
  19821. else if (this.target._y > this.area.y + this.area.height)
  19822. ty = this.area.y + this.area.height;
  19823. if (!isNaN(tx) || !isNaN(ty)) {
  19824. var obj = {};
  19825. if (!isNaN(tx))
  19826. obj.x = tx;
  19827. if (!isNaN(ty))
  19828. obj.y = ty;
  19829. this._tween = Tween.to(this.target, obj, this.elasticBackTime, Ease.sineOut, Handler.create(this, this.clear), 0, false, false);
  19830. }
  19831. else {
  19832. this.clear();
  19833. }
  19834. }
  19835. tweenMove() {
  19836. this._offsetX *= this.ratio * this._elasticRateX;
  19837. this._offsetY *= this.ratio * this._elasticRateY;
  19838. this.target.x += this._offsetX;
  19839. this.target.y += this._offsetY;
  19840. this.area && this.checkArea();
  19841. this.target.event(Event.DRAG_MOVE, this.data);
  19842. if ((Math.abs(this._offsetX) < 1 && Math.abs(this._offsetY) < 1) || this._elasticRateX < 0.5 || this._elasticRateY < 0.5) {
  19843. ILaya.systemTimer.clear(this, this.tweenMove);
  19844. if (this.elasticDistance > 0)
  19845. this.checkElastic();
  19846. else
  19847. this.clear();
  19848. }
  19849. }
  19850. clear() {
  19851. if (this.target) {
  19852. this.clearTimer();
  19853. var sp = this.target;
  19854. this.target = null;
  19855. this._parent = null;
  19856. sp.event(Event.DRAG_END, this.data);
  19857. }
  19858. }
  19859. }
  19860. class Component {
  19861. constructor() {
  19862. this._id = Utils.getGID();
  19863. this._resetComp();
  19864. }
  19865. get id() {
  19866. return this._id;
  19867. }
  19868. get enabled() {
  19869. return this._enabled;
  19870. }
  19871. set enabled(value) {
  19872. if (this._enabled != value) {
  19873. this._enabled = value;
  19874. if (this.owner) {
  19875. if (value)
  19876. this.owner.activeInHierarchy && this._onEnable();
  19877. else
  19878. this.owner.activeInHierarchy && this._onDisable();
  19879. }
  19880. }
  19881. }
  19882. get isSingleton() {
  19883. return true;
  19884. }
  19885. get destroyed() {
  19886. return this._destroyed;
  19887. }
  19888. _isScript() {
  19889. return false;
  19890. }
  19891. _resetComp() {
  19892. this._indexInList = -1;
  19893. this._enabled = true;
  19894. this._awaked = false;
  19895. this.owner = null;
  19896. }
  19897. _getIndexInList() {
  19898. return this._indexInList;
  19899. }
  19900. _setIndexInList(index) {
  19901. this._indexInList = index;
  19902. }
  19903. _onAdded() {
  19904. }
  19905. _onAwake() {
  19906. }
  19907. _onEnable() {
  19908. }
  19909. _onDisable() {
  19910. }
  19911. _onDestroy() {
  19912. }
  19913. onReset() {
  19914. }
  19915. _parse(data) {
  19916. }
  19917. _cloneTo(dest) {
  19918. }
  19919. _setActive(value) {
  19920. if (value) {
  19921. if (!this._awaked) {
  19922. this._awaked = true;
  19923. this._onAwake();
  19924. }
  19925. this._enabled && this._onEnable();
  19926. }
  19927. else {
  19928. this._enabled && this._onDisable();
  19929. }
  19930. }
  19931. destroy() {
  19932. if (this.owner)
  19933. this.owner._destroyComponent(this);
  19934. }
  19935. _destroy() {
  19936. if (this.owner.activeInHierarchy && this._enabled) {
  19937. this._setActive(false);
  19938. (this._isScript()) && (this.onDisable());
  19939. }
  19940. this._onDestroy();
  19941. this._destroyed = true;
  19942. if (this.onReset !== Component.prototype.onReset) {
  19943. this.onReset();
  19944. this._resetComp();
  19945. Pool.recoverByClass(this);
  19946. }
  19947. else {
  19948. this._resetComp();
  19949. }
  19950. }
  19951. }
  19952. class AnimationBase extends Sprite {
  19953. constructor() {
  19954. super();
  19955. this.wrapMode = 0;
  19956. this._interval = Config.animationInterval;
  19957. this._isReverse = false;
  19958. this._frameRateChanged = false;
  19959. this._setBitUp(Const.DISPLAY);
  19960. }
  19961. play(start = 0, loop = true, name = "") {
  19962. this._isPlaying = true;
  19963. this._actionName = name;
  19964. this.index = (typeof (start) == 'string') ? this._getFrameByLabel(start) : start;
  19965. this.loop = loop;
  19966. this._isReverse = this.wrapMode === AnimationBase.WRAP_REVERSE;
  19967. if (this.index == 0 && this._isReverse) {
  19968. this.index = this.count - 1;
  19969. }
  19970. if (this.interval > 0)
  19971. this.timerLoop(this.interval, this, this._frameLoop, null, true, true);
  19972. }
  19973. get interval() {
  19974. return this._interval;
  19975. }
  19976. set interval(value) {
  19977. if (this._interval != value) {
  19978. this._frameRateChanged = true;
  19979. this._interval = value;
  19980. if (this._isPlaying && value > 0) {
  19981. this.timerLoop(value, this, this._frameLoop, null, true, true);
  19982. }
  19983. }
  19984. }
  19985. _getFrameByLabel(label) {
  19986. for (var i = 0; i < this._count; i++) {
  19987. var item = this._labels[i];
  19988. if (item && item.indexOf(label) > -1)
  19989. return i;
  19990. }
  19991. return 0;
  19992. }
  19993. _frameLoop() {
  19994. if (this._isReverse) {
  19995. this._index--;
  19996. if (this._index < 0) {
  19997. if (this.loop) {
  19998. if (this.wrapMode == AnimationBase.WRAP_PINGPONG) {
  19999. this._index = this._count > 0 ? 1 : 0;
  20000. this._isReverse = false;
  20001. }
  20002. else {
  20003. this._index = this._count - 1;
  20004. }
  20005. this.event(Event.COMPLETE);
  20006. }
  20007. else {
  20008. this._index = 0;
  20009. this.stop();
  20010. this.event(Event.COMPLETE);
  20011. return;
  20012. }
  20013. }
  20014. }
  20015. else {
  20016. this._index++;
  20017. if (this._index >= this._count) {
  20018. if (this.loop) {
  20019. if (this.wrapMode == AnimationBase.WRAP_PINGPONG) {
  20020. this._index = this._count - 2 >= 0 ? this._count - 2 : 0;
  20021. this._isReverse = true;
  20022. }
  20023. else {
  20024. this._index = 0;
  20025. }
  20026. this.event(Event.COMPLETE);
  20027. }
  20028. else {
  20029. this._index--;
  20030. this.stop();
  20031. this.event(Event.COMPLETE);
  20032. return;
  20033. }
  20034. }
  20035. }
  20036. this.index = this._index;
  20037. }
  20038. _setControlNode(node) {
  20039. if (this._controlNode) {
  20040. this._controlNode.off(Event.DISPLAY, this, this._resumePlay);
  20041. this._controlNode.off(Event.UNDISPLAY, this, this._resumePlay);
  20042. }
  20043. this._controlNode = node;
  20044. if (node && node != this) {
  20045. node.on(Event.DISPLAY, this, this._resumePlay);
  20046. node.on(Event.UNDISPLAY, this, this._resumePlay);
  20047. }
  20048. }
  20049. _setDisplay(value) {
  20050. super._setDisplay(value);
  20051. this._resumePlay();
  20052. }
  20053. _resumePlay() {
  20054. if (this._isPlaying) {
  20055. if (this._controlNode.displayedInStage)
  20056. this.play(this._index, this.loop, this._actionName);
  20057. else
  20058. this.clearTimer(this, this._frameLoop);
  20059. }
  20060. }
  20061. stop() {
  20062. this._isPlaying = false;
  20063. this.clearTimer(this, this._frameLoop);
  20064. }
  20065. get isPlaying() {
  20066. return this._isPlaying;
  20067. }
  20068. addLabel(label, index) {
  20069. if (!this._labels)
  20070. this._labels = {};
  20071. if (!this._labels[index])
  20072. this._labels[index] = [];
  20073. this._labels[index].push(label);
  20074. }
  20075. removeLabel(label) {
  20076. if (!label)
  20077. this._labels = null;
  20078. else if (this._labels) {
  20079. for (var name in this._labels) {
  20080. this._removeLabelFromList(this._labels[name], label);
  20081. }
  20082. }
  20083. }
  20084. _removeLabelFromList(list, label) {
  20085. if (!list)
  20086. return;
  20087. for (var i = list.length - 1; i >= 0; i--) {
  20088. if (list[i] == label) {
  20089. list.splice(i, 1);
  20090. }
  20091. }
  20092. }
  20093. gotoAndStop(position) {
  20094. this.index = (typeof (position) == 'string') ? this._getFrameByLabel(position) : position;
  20095. this.stop();
  20096. }
  20097. get index() {
  20098. return this._index;
  20099. }
  20100. set index(value) {
  20101. this._index = value;
  20102. this._displayToIndex(value);
  20103. if (this._labels && this._labels[value]) {
  20104. var tArr = this._labels[value];
  20105. for (var i = 0, len = tArr.length; i < len; i++) {
  20106. this.event(Event.LABEL, tArr[i]);
  20107. }
  20108. }
  20109. }
  20110. _displayToIndex(value) {
  20111. }
  20112. get count() {
  20113. return this._count;
  20114. }
  20115. clear() {
  20116. this.stop();
  20117. this._labels = null;
  20118. return this;
  20119. }
  20120. }
  20121. AnimationBase.WRAP_POSITIVE = 0;
  20122. AnimationBase.WRAP_REVERSE = 1;
  20123. AnimationBase.WRAP_PINGPONG = 2;
  20124. ClassUtils.regClass("laya.display.AnimationBase", AnimationBase);
  20125. ClassUtils.regClass("Laya.AnimationBase", AnimationBase);
  20126. class MathUtil {
  20127. static subtractVector3(l, r, o) {
  20128. o[0] = l[0] - r[0];
  20129. o[1] = l[1] - r[1];
  20130. o[2] = l[2] - r[2];
  20131. }
  20132. static lerp(left, right, amount) {
  20133. return left * (1 - amount) + right * amount;
  20134. }
  20135. static scaleVector3(f, b, e) {
  20136. e[0] = f[0] * b;
  20137. e[1] = f[1] * b;
  20138. e[2] = f[2] * b;
  20139. }
  20140. static lerpVector3(l, r, t, o) {
  20141. var ax = l[0], ay = l[1], az = l[2];
  20142. o[0] = ax + t * (r[0] - ax);
  20143. o[1] = ay + t * (r[1] - ay);
  20144. o[2] = az + t * (r[2] - az);
  20145. }
  20146. static lerpVector4(l, r, t, o) {
  20147. var ax = l[0], ay = l[1], az = l[2], aw = l[3];
  20148. o[0] = ax + t * (r[0] - ax);
  20149. o[1] = ay + t * (r[1] - ay);
  20150. o[2] = az + t * (r[2] - az);
  20151. o[3] = aw + t * (r[3] - aw);
  20152. }
  20153. static slerpQuaternionArray(a, Offset1, b, Offset2, t, out, Offset3) {
  20154. 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];
  20155. var omega, cosom, sinom, scale0, scale1;
  20156. cosom = ax * bx + ay * by + az * bz + aw * bw;
  20157. if (cosom < 0.0) {
  20158. cosom = -cosom;
  20159. bx = -bx;
  20160. by = -by;
  20161. bz = -bz;
  20162. bw = -bw;
  20163. }
  20164. if ((1.0 - cosom) > 0.000001) {
  20165. omega = Math.acos(cosom);
  20166. sinom = Math.sin(omega);
  20167. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  20168. scale1 = Math.sin(t * omega) / sinom;
  20169. }
  20170. else {
  20171. scale0 = 1.0 - t;
  20172. scale1 = t;
  20173. }
  20174. out[Offset3 + 0] = scale0 * ax + scale1 * bx;
  20175. out[Offset3 + 1] = scale0 * ay + scale1 * by;
  20176. out[Offset3 + 2] = scale0 * az + scale1 * bz;
  20177. out[Offset3 + 3] = scale0 * aw + scale1 * bw;
  20178. return out;
  20179. }
  20180. static getRotation(x0, y0, x1, y1) {
  20181. return Math.atan2(y1 - y0, x1 - x0) / Math.PI * 180;
  20182. }
  20183. static sortBigFirst(a, b) {
  20184. if (a == b)
  20185. return 0;
  20186. return b > a ? 1 : -1;
  20187. }
  20188. static sortSmallFirst(a, b) {
  20189. if (a == b)
  20190. return 0;
  20191. return b > a ? -1 : 1;
  20192. }
  20193. static sortNumBigFirst(a, b) {
  20194. return parseFloat(b) - parseFloat(a);
  20195. }
  20196. static sortNumSmallFirst(a, b) {
  20197. return parseFloat(a) - parseFloat(b);
  20198. }
  20199. static sortByKey(key, bigFirst = false, forceNum = true) {
  20200. var _sortFun;
  20201. if (bigFirst) {
  20202. _sortFun = forceNum ? MathUtil.sortNumBigFirst : MathUtil.sortBigFirst;
  20203. }
  20204. else {
  20205. _sortFun = forceNum ? MathUtil.sortNumSmallFirst : MathUtil.sortSmallFirst;
  20206. }
  20207. return function (a, b) {
  20208. return _sortFun(a[key], b[key]);
  20209. };
  20210. }
  20211. }
  20212. class FrameAnimation extends AnimationBase {
  20213. constructor() {
  20214. super();
  20215. if (FrameAnimation._sortIndexFun === null) {
  20216. FrameAnimation._sortIndexFun = MathUtil.sortByKey("index", false, true);
  20217. }
  20218. }
  20219. _setUp(targetDic, animationData) {
  20220. this._targetDic = targetDic;
  20221. this._animationData = animationData;
  20222. this.interval = 1000 / animationData.frameRate;
  20223. if (animationData.parsed) {
  20224. this._count = animationData.count;
  20225. this._labels = animationData.labels;
  20226. this._usedFrames = animationData.animationNewFrames;
  20227. }
  20228. else {
  20229. this._usedFrames = [];
  20230. this._calculateDatas();
  20231. animationData.parsed = true;
  20232. animationData.labels = this._labels;
  20233. animationData.count = this._count;
  20234. animationData.animationNewFrames = this._usedFrames;
  20235. }
  20236. }
  20237. clear() {
  20238. super.clear();
  20239. this._targetDic = null;
  20240. this._animationData = null;
  20241. return this;
  20242. }
  20243. _displayToIndex(value) {
  20244. if (!this._animationData)
  20245. return;
  20246. if (value < 0)
  20247. value = 0;
  20248. if (value > this._count)
  20249. value = this._count;
  20250. var nodes = this._animationData.nodes, i, len = nodes.length;
  20251. for (i = 0; i < len; i++) {
  20252. this._displayNodeToFrame(nodes[i], value);
  20253. }
  20254. }
  20255. _displayNodeToFrame(node, frame, targetDic = null) {
  20256. if (!targetDic)
  20257. targetDic = this._targetDic;
  20258. var target = targetDic[node.target];
  20259. if (!target) {
  20260. return;
  20261. }
  20262. var frames = node.frames, key, propFrames, value;
  20263. var keys = node.keys, i, len = keys.length;
  20264. for (i = 0; i < len; i++) {
  20265. key = keys[i];
  20266. propFrames = frames[key];
  20267. if (propFrames.length > frame) {
  20268. value = propFrames[frame];
  20269. }
  20270. else {
  20271. value = propFrames[propFrames.length - 1];
  20272. }
  20273. target[key] = value;
  20274. }
  20275. var funkeys = node.funkeys;
  20276. len = funkeys.length;
  20277. var funFrames;
  20278. if (len == 0)
  20279. return;
  20280. for (i = 0; i < len; i++) {
  20281. key = funkeys[i];
  20282. funFrames = frames[key];
  20283. if (funFrames[frame] !== undefined) {
  20284. target[key] && target[key].apply(target, funFrames[frame]);
  20285. }
  20286. }
  20287. }
  20288. _calculateDatas() {
  20289. if (!this._animationData)
  20290. return;
  20291. var nodes = this._animationData.nodes, i, len = nodes.length, tNode;
  20292. this._count = 0;
  20293. for (i = 0; i < len; i++) {
  20294. tNode = nodes[i];
  20295. this._calculateKeyFrames(tNode);
  20296. }
  20297. this._count += 1;
  20298. }
  20299. _calculateKeyFrames(node) {
  20300. var keyFrames = node.keyframes, key, tKeyFrames, target = node.target;
  20301. if (!node.frames)
  20302. node.frames = {};
  20303. if (!node.keys)
  20304. node.keys = [];
  20305. else
  20306. node.keys.length = 0;
  20307. if (!node.funkeys)
  20308. node.funkeys = [];
  20309. else
  20310. node.funkeys.length = 0;
  20311. if (!node.initValues)
  20312. node.initValues = {};
  20313. for (key in keyFrames) {
  20314. var isFun = key.indexOf("()") != -1;
  20315. tKeyFrames = keyFrames[key];
  20316. if (isFun)
  20317. key = key.substr(0, key.length - 2);
  20318. if (!node.frames[key]) {
  20319. node.frames[key] = [];
  20320. }
  20321. if (!isFun) {
  20322. if (this._targetDic && this._targetDic[target]) {
  20323. node.initValues[key] = this._targetDic[target][key];
  20324. }
  20325. tKeyFrames.sort(FrameAnimation._sortIndexFun);
  20326. node.keys.push(key);
  20327. this._calculateNodePropFrames(tKeyFrames, node.frames[key], key, target);
  20328. }
  20329. else {
  20330. node.funkeys.push(key);
  20331. var map = node.frames[key];
  20332. for (var i = 0; i < tKeyFrames.length; i++) {
  20333. var temp = tKeyFrames[i];
  20334. map[temp.index] = temp.value;
  20335. if (temp.index > this._count)
  20336. this._count = temp.index;
  20337. }
  20338. }
  20339. }
  20340. }
  20341. resetNodes() {
  20342. if (!this._targetDic)
  20343. return;
  20344. if (!this._animationData)
  20345. return;
  20346. var nodes = this._animationData.nodes, i, len = nodes.length;
  20347. var tNode;
  20348. var initValues;
  20349. for (i = 0; i < len; i++) {
  20350. tNode = nodes[i];
  20351. initValues = tNode.initValues;
  20352. if (!initValues)
  20353. continue;
  20354. var target = this._targetDic[tNode.target];
  20355. if (!target)
  20356. continue;
  20357. var key;
  20358. for (key in initValues) {
  20359. target[key] = initValues[key];
  20360. }
  20361. }
  20362. }
  20363. _calculateNodePropFrames(keyframes, frames, key, target) {
  20364. var i, len = keyframes.length - 1;
  20365. frames.length = keyframes[len].index + 1;
  20366. for (i = 0; i < len; i++) {
  20367. this._dealKeyFrame(keyframes[i]);
  20368. this._calculateFrameValues(keyframes[i], keyframes[i + 1], frames);
  20369. }
  20370. if (len == 0) {
  20371. frames[0] = keyframes[0].value;
  20372. if (this._usedFrames)
  20373. this._usedFrames[keyframes[0].index] = true;
  20374. }
  20375. this._dealKeyFrame(keyframes[i]);
  20376. }
  20377. _dealKeyFrame(keyFrame) {
  20378. if (keyFrame.label && keyFrame.label != "")
  20379. this.addLabel(keyFrame.label, keyFrame.index);
  20380. }
  20381. _calculateFrameValues(startFrame, endFrame, result) {
  20382. var i, easeFun;
  20383. var start = startFrame.index, end = endFrame.index;
  20384. var startValue = startFrame.value;
  20385. var dValue = endFrame.value - startFrame.value;
  20386. var dLen = end - start;
  20387. var frames = this._usedFrames;
  20388. if (end > this._count)
  20389. this._count = end;
  20390. if (startFrame.tween) {
  20391. easeFun = Ease[startFrame.tweenMethod];
  20392. if (easeFun == null)
  20393. easeFun = Ease.linearNone;
  20394. for (i = start; i < end; i++) {
  20395. result[i] = easeFun(i - start, startValue, dValue, dLen);
  20396. if (frames)
  20397. frames[i] = true;
  20398. }
  20399. }
  20400. else {
  20401. for (i = start; i < end; i++) {
  20402. result[i] = startValue;
  20403. }
  20404. }
  20405. if (frames) {
  20406. frames[startFrame.index] = true;
  20407. frames[endFrame.index] = true;
  20408. }
  20409. result[endFrame.index] = endFrame.value;
  20410. }
  20411. }
  20412. ClassUtils.regClass("laya.display.FrameAnimation", FrameAnimation);
  20413. ClassUtils.regClass("Laya.FrameAnimation", FrameAnimation);
  20414. var supportWeakMap = !!WeakMap;
  20415. class WeakObject {
  20416. constructor() {
  20417. this._obj = WeakObject.supportWeakMap ? new Browser.window.WeakMap() : {};
  20418. if (!WeakObject.supportWeakMap)
  20419. WeakObject._maps.push(this);
  20420. }
  20421. static __init__() {
  20422. WeakObject.I = new WeakObject();
  20423. if (!WeakObject.supportWeakMap)
  20424. ILaya.systemTimer.loop(WeakObject.delInterval, null, WeakObject.clearCache);
  20425. }
  20426. static clearCache() {
  20427. for (var i = 0, n = WeakObject._maps.length; i < n; i++) {
  20428. var obj = WeakObject._maps[i];
  20429. obj._obj = {};
  20430. }
  20431. }
  20432. set(key, value) {
  20433. if (key == null)
  20434. return;
  20435. if (WeakObject.supportWeakMap) {
  20436. var objKey = key;
  20437. if (typeof (key) == 'string' || typeof (key) == 'number') {
  20438. objKey = WeakObject._keys[key];
  20439. if (!objKey)
  20440. objKey = WeakObject._keys[key] = { k: key };
  20441. }
  20442. this._obj.set(objKey, value);
  20443. }
  20444. else {
  20445. if (typeof (key) == 'string' || typeof (key) == 'number') {
  20446. this._obj[key] = value;
  20447. }
  20448. else {
  20449. key.$_GID || (key.$_GID = Utils.getGID());
  20450. this._obj[key.$_GID] = value;
  20451. }
  20452. }
  20453. }
  20454. get(key) {
  20455. if (key == null)
  20456. return null;
  20457. if (WeakObject.supportWeakMap) {
  20458. var objKey = (typeof (key) == 'string' || typeof (key) == 'number') ? WeakObject._keys[key] : key;
  20459. if (!objKey)
  20460. return null;
  20461. return this._obj.get(objKey);
  20462. }
  20463. else {
  20464. if (typeof (key) == 'string' || typeof (key) == 'number')
  20465. return this._obj[key];
  20466. return this._obj[key.$_GID];
  20467. }
  20468. }
  20469. del(key) {
  20470. if (key == null)
  20471. return;
  20472. if (WeakObject.supportWeakMap) {
  20473. var objKey = (typeof (key) == 'string' || typeof (key) == 'number') ? WeakObject._keys[key] : key;
  20474. if (!objKey)
  20475. return;
  20476. this._obj.delete(objKey);
  20477. }
  20478. else {
  20479. if (typeof (key) == 'string' || typeof (key) == 'number')
  20480. delete this._obj[key];
  20481. else
  20482. delete this._obj[this._obj.$_GID];
  20483. }
  20484. }
  20485. has(key) {
  20486. if (key == null)
  20487. return false;
  20488. if (WeakObject.supportWeakMap) {
  20489. var objKey = (typeof (key) == 'string' || typeof (key) == 'number') ? WeakObject._keys[key] : key;
  20490. return this._obj.has(objKey);
  20491. }
  20492. else {
  20493. if (typeof (key) == 'string' || typeof (key) == 'number')
  20494. return this._obj[key] != null;
  20495. return this._obj[this._obj.$_GID] != null;
  20496. }
  20497. }
  20498. }
  20499. WeakObject.supportWeakMap = supportWeakMap;
  20500. WeakObject.delInterval = 10 * 60 * 1000;
  20501. WeakObject._keys = {};
  20502. WeakObject._maps = [];
  20503. class SceneUtils {
  20504. static __init() {
  20505. SceneUtils._funMap = new WeakObject();
  20506. }
  20507. static getBindFun(value) {
  20508. var fun = SceneUtils._funMap.get(value);
  20509. if (fun == null) {
  20510. var temp = "\"" + value + "\"";
  20511. temp = temp.replace(/^"\${|}"$/g, "").replace(/\${/g, "\"+").replace(/}/g, "+\"");
  20512. var str = "(function(data){if(data==null)return;with(data){try{\nreturn " + temp + "\n}catch(e){}}})";
  20513. fun = window.Laya._runScript(str);
  20514. SceneUtils._funMap.set(value, fun);
  20515. }
  20516. return fun;
  20517. }
  20518. static createByData(root, uiView) {
  20519. var tInitTool = InitTool.create();
  20520. root = SceneUtils.createComp(uiView, root, root, null, tInitTool);
  20521. root._setBit(Const.NOT_READY, true);
  20522. if ("_idMap" in root) {
  20523. root["_idMap"] = tInitTool._idMap;
  20524. }
  20525. if (uiView.animations) {
  20526. var anilist = [];
  20527. var animations = uiView.animations;
  20528. var i, len = animations.length;
  20529. var tAni;
  20530. var tAniO;
  20531. for (i = 0; i < len; i++) {
  20532. tAni = new FrameAnimation();
  20533. tAniO = animations[i];
  20534. tAni._setUp(tInitTool._idMap, tAniO);
  20535. root[tAniO.name] = tAni;
  20536. tAni._setControlNode(root);
  20537. switch (tAniO.action) {
  20538. case 1:
  20539. tAni.play(0, false);
  20540. break;
  20541. case 2:
  20542. tAni.play(0, true);
  20543. break;
  20544. }
  20545. anilist.push(tAni);
  20546. }
  20547. root._aniList = anilist;
  20548. }
  20549. if (root._$componentType === "Scene" && root._width > 0 && uiView.props.hitTestPrior == null && !root.mouseThrough)
  20550. root.hitTestPrior = true;
  20551. tInitTool.beginLoad(root);
  20552. return root;
  20553. }
  20554. static createInitTool() {
  20555. return InitTool.create();
  20556. }
  20557. static createComp(uiView, comp = null, view = null, dataMap = null, initTool = null) {
  20558. if (uiView.type == "Scene3D" || uiView.type == "Sprite3D") {
  20559. var outBatchSprits = [];
  20560. var scene3D = ILaya.Laya["Utils3D"]._createSceneByJsonForMaker(uiView, outBatchSprits, initTool);
  20561. if (uiView.type == "Sprite3D")
  20562. ILaya.Laya["StaticBatchManager"].combine(scene3D, outBatchSprits);
  20563. else
  20564. ILaya.Laya["StaticBatchManager"].combine(null, outBatchSprits);
  20565. return scene3D;
  20566. }
  20567. comp = comp || SceneUtils.getCompInstance(uiView);
  20568. if (!comp) {
  20569. if (uiView.props && uiView.props.runtime)
  20570. console.warn("runtime not found:" + uiView.props.runtime);
  20571. else
  20572. console.warn("can not create:" + uiView.type);
  20573. return null;
  20574. }
  20575. var child = uiView.child;
  20576. if (child) {
  20577. var isList = comp["_$componentType"] == "List";
  20578. for (var i = 0, n = child.length; i < n; i++) {
  20579. var node = child[i];
  20580. if ('itemRender' in comp && (node.props.name == "render" || node.props.renderType === "render")) {
  20581. comp["itemRender"] = node;
  20582. }
  20583. else if (node.type == "Graphic") {
  20584. ILaya.ClassUtils._addGraphicsToSprite(node, comp);
  20585. }
  20586. else if (ILaya.ClassUtils._isDrawType(node.type)) {
  20587. ILaya.ClassUtils._addGraphicToSprite(node, comp, true);
  20588. }
  20589. else {
  20590. if (isList) {
  20591. var arr = [];
  20592. var tChild = SceneUtils.createComp(node, null, view, arr, initTool);
  20593. if (arr.length)
  20594. tChild["_$bindData"] = arr;
  20595. }
  20596. else {
  20597. tChild = SceneUtils.createComp(node, null, view, dataMap, initTool);
  20598. }
  20599. if (node.type == "Script") {
  20600. if (tChild instanceof Component) {
  20601. comp._addComponentInstance(tChild);
  20602. }
  20603. else {
  20604. if ("owner" in tChild) {
  20605. tChild["owner"] = comp;
  20606. }
  20607. else if ("target" in tChild) {
  20608. tChild["target"] = comp;
  20609. }
  20610. }
  20611. }
  20612. else if (node.props.renderType == "mask" || node.props.name == "mask") {
  20613. comp.mask = tChild;
  20614. }
  20615. else {
  20616. tChild instanceof Node && comp.addChild(tChild);
  20617. }
  20618. }
  20619. }
  20620. }
  20621. var props = uiView.props;
  20622. for (var prop in props) {
  20623. var value = props[prop];
  20624. if (typeof (value) == 'string' && (value.indexOf("@node:") >= 0 || value.indexOf("@Prefab:") >= 0)) {
  20625. if (initTool) {
  20626. initTool.addNodeRef(comp, prop, value);
  20627. }
  20628. }
  20629. else
  20630. SceneUtils.setCompValue(comp, prop, value, view, dataMap);
  20631. }
  20632. if (comp._afterInited) {
  20633. comp._afterInited();
  20634. }
  20635. if (uiView.compId && initTool && initTool._idMap) {
  20636. initTool._idMap[uiView.compId] = comp;
  20637. }
  20638. return comp;
  20639. }
  20640. static setCompValue(comp, prop, value, view = null, dataMap = null) {
  20641. if (typeof (value) == 'string' && value.indexOf("${") > -1) {
  20642. SceneUtils._sheet || (SceneUtils._sheet = ILaya.ClassUtils.getClass("laya.data.Table"));
  20643. if (!SceneUtils._sheet) {
  20644. console.warn("Can not find class Sheet");
  20645. return;
  20646. }
  20647. if (dataMap) {
  20648. dataMap.push(comp, prop, value);
  20649. }
  20650. else if (view) {
  20651. if (value.indexOf("].") == -1) {
  20652. value = value.replace(".", "[0].");
  20653. }
  20654. var watcher = new DataWatcher(comp, prop, value);
  20655. watcher.exe(view);
  20656. var one, temp;
  20657. var str = value.replace(/\[.*?\]\./g, ".");
  20658. while ((one = SceneUtils._parseWatchData.exec(str)) != null) {
  20659. var key1 = one[1];
  20660. while ((temp = SceneUtils._parseKeyWord.exec(key1)) != null) {
  20661. var key2 = temp[0];
  20662. var arr = (view._watchMap[key2] || (view._watchMap[key2] = []));
  20663. arr.push(watcher);
  20664. SceneUtils._sheet.I.notifer.on(key2, view, view.changeData, [key2]);
  20665. }
  20666. arr = (view._watchMap[key1] || (view._watchMap[key1] = []));
  20667. arr.push(watcher);
  20668. SceneUtils._sheet.I.notifer.on(key1, view, view.changeData, [key1]);
  20669. }
  20670. }
  20671. return;
  20672. }
  20673. if (prop === "var" && view) {
  20674. view[value] = comp;
  20675. }
  20676. else {
  20677. comp[prop] = (value === "true" ? true : (value === "false" ? false : value));
  20678. }
  20679. }
  20680. static getCompInstance(json) {
  20681. if (json.type == "UIView") {
  20682. if (json.props && json.props.pageData) {
  20683. return SceneUtils.createByData(null, json.props.pageData);
  20684. }
  20685. }
  20686. var runtime = (json.props && json.props.runtime) || json.type;
  20687. var compClass = ILaya.ClassUtils.getClass(runtime);
  20688. if (!compClass)
  20689. throw "Can not find class " + runtime;
  20690. if (json.type === "Script" && compClass.prototype._doAwake) {
  20691. var comp = Pool.createByClass(compClass);
  20692. comp._destroyed = false;
  20693. return comp;
  20694. }
  20695. if (json.props && "renderType" in json.props && json.props["renderType"] == "instance") {
  20696. if (!compClass["instance"])
  20697. compClass["instance"] = new compClass();
  20698. return compClass["instance"];
  20699. }
  20700. return new compClass();
  20701. }
  20702. }
  20703. SceneUtils._parseWatchData = /\${(.*?)}/g;
  20704. SceneUtils._parseKeyWord = /[a-zA-Z_][a-zA-Z0-9_]*(?:(?:\.[a-zA-Z_][a-zA-Z0-9_]*)+)/g;
  20705. class DataWatcher {
  20706. constructor(comp, prop, value) {
  20707. this.comp = comp;
  20708. this.prop = prop;
  20709. this.value = value;
  20710. }
  20711. exe(view) {
  20712. var fun = SceneUtils.getBindFun(this.value);
  20713. this.comp[this.prop] = fun.call(this, view);
  20714. }
  20715. }
  20716. class InitTool {
  20717. reset() {
  20718. this._nodeRefList = null;
  20719. this._initList = null;
  20720. this._idMap = null;
  20721. this._loadList = null;
  20722. this._scene = null;
  20723. }
  20724. recover() {
  20725. this.reset();
  20726. Pool.recover("InitTool", this);
  20727. }
  20728. static create() {
  20729. var tool = Pool.getItemByClass("InitTool", InitTool);
  20730. tool._idMap = [];
  20731. return tool;
  20732. }
  20733. addLoadRes(url, type = null) {
  20734. if (!this._loadList)
  20735. this._loadList = [];
  20736. if (!type) {
  20737. this._loadList.push(url);
  20738. }
  20739. else {
  20740. this._loadList.push({ url: url, type: type });
  20741. }
  20742. }
  20743. addNodeRef(node, prop, referStr) {
  20744. if (!this._nodeRefList)
  20745. this._nodeRefList = [];
  20746. this._nodeRefList.push([node, prop, referStr]);
  20747. if (referStr.indexOf("@Prefab:") >= 0) {
  20748. this.addLoadRes(referStr.replace("@Prefab:", ""), Loader.PREFAB);
  20749. }
  20750. }
  20751. setNodeRef() {
  20752. if (!this._nodeRefList)
  20753. return;
  20754. if (!this._idMap) {
  20755. this._nodeRefList = null;
  20756. return;
  20757. }
  20758. var i, len;
  20759. len = this._nodeRefList.length;
  20760. var tRefInfo;
  20761. for (i = 0; i < len; i++) {
  20762. tRefInfo = this._nodeRefList[i];
  20763. tRefInfo[0][tRefInfo[1]] = this.getReferData(tRefInfo[2]);
  20764. }
  20765. this._nodeRefList = null;
  20766. }
  20767. getReferData(referStr) {
  20768. if (referStr.indexOf("@Prefab:") >= 0) {
  20769. var prefab;
  20770. prefab = Loader.getRes(referStr.replace("@Prefab:", ""));
  20771. return prefab;
  20772. }
  20773. else if (referStr.indexOf("@arr:") >= 0) {
  20774. referStr = referStr.replace("@arr:", "");
  20775. var list;
  20776. list = referStr.split(",");
  20777. var i, len;
  20778. var tStr;
  20779. len = list.length;
  20780. for (i = 0; i < len; i++) {
  20781. tStr = list[i];
  20782. if (tStr) {
  20783. list[i] = this._idMap[tStr.replace("@node:", "")];
  20784. }
  20785. else {
  20786. list[i] = null;
  20787. }
  20788. }
  20789. return list;
  20790. }
  20791. else {
  20792. return this._idMap[referStr.replace("@node:", "")];
  20793. }
  20794. }
  20795. addInitItem(item) {
  20796. if (!this._initList)
  20797. this._initList = [];
  20798. this._initList.push(item);
  20799. }
  20800. doInits() {
  20801. if (!this._initList)
  20802. return;
  20803. this._initList = null;
  20804. }
  20805. finish() {
  20806. this.setNodeRef();
  20807. this.doInits();
  20808. this._scene._setBit(Const.NOT_READY, false);
  20809. if (this._scene.parent && this._scene.parent.activeInHierarchy && this._scene.active)
  20810. this._scene._processActive();
  20811. this._scene.event("onViewCreated");
  20812. this.recover();
  20813. }
  20814. beginLoad(scene) {
  20815. this._scene = scene;
  20816. if (!this._loadList || this._loadList.length < 1) {
  20817. this.finish();
  20818. }
  20819. else {
  20820. ILaya.loader.load(this._loadList, Handler.create(this, this.finish));
  20821. }
  20822. }
  20823. }
  20824. class IStatRender {
  20825. show(x = 0, y = 0) {
  20826. }
  20827. enable() {
  20828. }
  20829. hide() {
  20830. }
  20831. set_onclick(fn) {
  20832. }
  20833. isCanvasRender() {
  20834. return true;
  20835. }
  20836. renderNotCanvas(ctx, x, y) { }
  20837. }
  20838. class StatUI extends IStatRender {
  20839. constructor() {
  20840. super(...arguments);
  20841. this._show = false;
  20842. this._useCanvas = false;
  20843. this._height = 100;
  20844. this._view = [];
  20845. }
  20846. show(x = 0, y = 0) {
  20847. if (!Browser.onMiniGame && !ILaya.Render.isConchApp && !Browser.onBDMiniGame && !Browser.onKGMiniGame && !Browser.onQGMiniGame && !Browser.onQQMiniGame)
  20848. this._useCanvas = true;
  20849. this._show = true;
  20850. Stat._fpsData.length = 60;
  20851. this._view[0] = { title: "FPS(Canvas)", value: "_fpsStr", color: "yellow", units: "int" };
  20852. this._view[1] = { title: "Sprite", value: "_spriteStr", color: "white", units: "int" };
  20853. this._view[2] = { title: "RenderBatches", value: "renderBatches", color: "white", units: "int" };
  20854. this._view[3] = { title: "SavedRenderBatches", value: "savedRenderBatches", color: "white", units: "int" };
  20855. this._view[4] = { title: "CPUMemory", value: "cpuMemory", color: "yellow", units: "M" };
  20856. this._view[5] = { title: "GPUMemory", value: "gpuMemory", color: "yellow", units: "M" };
  20857. this._view[6] = { title: "Shader", value: "shaderCall", color: "white", units: "int" };
  20858. if (!Render.is3DMode) {
  20859. this._view[0].title = "FPS(WebGL)";
  20860. this._view[7] = { title: "Canvas", value: "_canvasStr", color: "white", units: "int" };
  20861. }
  20862. else {
  20863. this._view[0].title = "FPS(3D)";
  20864. this._view[7] = { title: "TriFaces", value: "trianglesFaces", color: "white", units: "int" };
  20865. this._view[8] = { title: "FrustumCulling", value: "frustumCulling", color: "white", units: "int" };
  20866. this._view[9] = { title: "OctreeNodeCulling", value: "octreeNodeCulling", color: "white", units: "int" };
  20867. }
  20868. if (this._useCanvas) {
  20869. this.createUIPre(x, y);
  20870. }
  20871. else
  20872. this.createUI(x, y);
  20873. this.enable();
  20874. }
  20875. createUIPre(x, y) {
  20876. var pixel = Browser.pixelRatio;
  20877. this._width = pixel * 180;
  20878. this._vx = pixel * 120;
  20879. this._height = pixel * (this._view.length * 12 + 3 * pixel) + 4;
  20880. StatUI._fontSize = 12 * pixel;
  20881. for (var i = 0; i < this._view.length; i++) {
  20882. this._view[i].x = 4;
  20883. this._view[i].y = i * StatUI._fontSize + 2 * pixel;
  20884. }
  20885. if (!this._canvas) {
  20886. this._canvas = new HTMLCanvas(true);
  20887. this._canvas.size(this._width, this._height);
  20888. this._ctx = this._canvas.getContext('2d');
  20889. this._ctx.textBaseline = "top";
  20890. this._ctx.font = StatUI._fontSize + "px Arial";
  20891. 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;";
  20892. }
  20893. if (!Browser.onKGMiniGame) {
  20894. Browser.container.appendChild(this._canvas.source);
  20895. }
  20896. this._first = true;
  20897. this.loop();
  20898. this._first = false;
  20899. }
  20900. createUI(x, y) {
  20901. var stat = this._sp;
  20902. var pixel = Browser.pixelRatio;
  20903. if (!stat) {
  20904. stat = new Sprite();
  20905. this._leftText = new Text();
  20906. this._leftText.pos(5, 5);
  20907. this._leftText.color = "#ffffff";
  20908. stat.addChild(this._leftText);
  20909. this._txt = new Text();
  20910. this._txt.pos(80 * pixel, 5);
  20911. this._txt.color = "#ffffff";
  20912. stat.addChild(this._txt);
  20913. this._sp = stat;
  20914. }
  20915. stat.pos(x, y);
  20916. var text = "";
  20917. for (var i = 0; i < this._view.length; i++) {
  20918. var one = this._view[i];
  20919. text += one.title + "\n";
  20920. }
  20921. this._leftText.text = text;
  20922. var width = pixel * 138;
  20923. var height = pixel * (this._view.length * 12 + 3 * pixel) + 4;
  20924. this._txt.fontSize = StatUI._fontSize * pixel;
  20925. this._leftText.fontSize = StatUI._fontSize * pixel;
  20926. stat.size(width, height);
  20927. stat.graphics.clear();
  20928. stat.graphics.alpha(0.5);
  20929. stat.graphics.drawRect(0, 0, width, height, "#999999");
  20930. stat.graphics.alpha(2);
  20931. this.loop();
  20932. }
  20933. enable() {
  20934. ILaya.systemTimer.frameLoop(1, this, this.loop);
  20935. }
  20936. hide() {
  20937. this._show = false;
  20938. ILaya.systemTimer.clear(this, this.loop);
  20939. if (this._canvas) {
  20940. Browser.removeElement(this._canvas.source);
  20941. }
  20942. }
  20943. set_onclick(fn) {
  20944. if (this._sp) {
  20945. this._sp.on("click", this._sp, fn);
  20946. }
  20947. if (this._canvas) {
  20948. this._canvas.source.onclick = fn;
  20949. this._canvas.source.style.pointerEvents = '';
  20950. }
  20951. }
  20952. loop() {
  20953. Stat._count++;
  20954. var timer = Browser.now();
  20955. if (timer - Stat._timer < 1000)
  20956. return;
  20957. var count = Stat._count;
  20958. Stat.FPS = Math.round((count * 1000) / (timer - Stat._timer));
  20959. if (this._show) {
  20960. Stat.trianglesFaces = Math.round(Stat.trianglesFaces / count);
  20961. if (!this._useCanvas) {
  20962. Stat.renderBatches = Math.round(Stat.renderBatches / count) - 1;
  20963. }
  20964. else {
  20965. Stat.renderBatches = Math.round(Stat.renderBatches / count);
  20966. }
  20967. Stat.savedRenderBatches = Math.round(Stat.savedRenderBatches / count);
  20968. Stat.shaderCall = Math.round(Stat.shaderCall / count);
  20969. Stat.spriteRenderUseCacheCount = Math.round(Stat.spriteRenderUseCacheCount / count);
  20970. Stat.canvasNormal = Math.round(Stat.canvasNormal / count);
  20971. Stat.canvasBitmap = Math.round(Stat.canvasBitmap / count);
  20972. Stat.canvasReCache = Math.ceil(Stat.canvasReCache / count);
  20973. Stat.frustumCulling = Math.round(Stat.frustumCulling / count);
  20974. Stat.octreeNodeCulling = Math.round(Stat.octreeNodeCulling / count);
  20975. var delay = Stat.FPS > 0 ? Math.floor(1000 / Stat.FPS).toString() : " ";
  20976. Stat._fpsStr = Stat.FPS + (Stat.renderSlow ? " slow" : "") + " " + delay;
  20977. Stat._spriteStr = Stat.spriteCount + (Stat.spriteRenderUseCacheCount ? ("/" + Stat.spriteRenderUseCacheCount) : '');
  20978. Stat._canvasStr = Stat.canvasReCache + "/" + Stat.canvasNormal + "/" + Stat.canvasBitmap;
  20979. Stat.cpuMemory = Resource.cpuMemory;
  20980. Stat.gpuMemory = Resource.gpuMemory;
  20981. if (this._useCanvas) {
  20982. this.renderInfoPre();
  20983. }
  20984. else
  20985. this.renderInfo();
  20986. Stat.clear();
  20987. }
  20988. Stat._count = 0;
  20989. Stat._timer = timer;
  20990. }
  20991. renderInfoPre() {
  20992. var i = 0;
  20993. var one;
  20994. var value;
  20995. if (this._canvas) {
  20996. var ctx = this._ctx;
  20997. ctx.clearRect(this._first ? 0 : this._vx, 0, this._width, this._height);
  20998. for (i = 0; i < this._view.length; i++) {
  20999. one = this._view[i];
  21000. if (this._first) {
  21001. ctx.fillStyle = "white";
  21002. ctx.fillText(one.title, one.x, one.y);
  21003. }
  21004. ctx.fillStyle = one.color;
  21005. value = Stat[one.value];
  21006. (one.units == "M") && (value = Math.floor(value / (1024 * 1024) * 100) / 100 + " M");
  21007. ctx.fillText(value + "", one.x + this._vx, one.y);
  21008. }
  21009. }
  21010. }
  21011. renderInfo() {
  21012. var text = "";
  21013. for (var i = 0; i < this._view.length; i++) {
  21014. var one = this._view[i];
  21015. var value = Stat[one.value];
  21016. (one.units == "M") && (value = Math.floor(value / (1024 * 1024) * 100) / 100 + " M");
  21017. (one.units == "K") && (value = Math.floor(value / (1024) * 100) / 100 + " K");
  21018. text += value + "\n";
  21019. }
  21020. this._txt.text = text;
  21021. }
  21022. isCanvasRender() {
  21023. return this._useCanvas;
  21024. }
  21025. renderNotCanvas(ctx, x, y) {
  21026. this._show && this._sp && this._sp.render(ctx, 0, 0);
  21027. }
  21028. }
  21029. StatUI._fontSize = 12;
  21030. class Timer {
  21031. constructor(autoActive = true) {
  21032. this.scale = 1;
  21033. this.currTimer = Date.now();
  21034. this.currFrame = 0;
  21035. this._delta = 0;
  21036. this._lastTimer = Date.now();
  21037. this._map = [];
  21038. this._handlers = [];
  21039. this._temp = [];
  21040. this._count = 0;
  21041. autoActive && Timer.gSysTimer && Timer.gSysTimer.frameLoop(1, this, this._update);
  21042. }
  21043. get delta() {
  21044. return this._delta;
  21045. }
  21046. _update() {
  21047. if (this.scale <= 0) {
  21048. this._lastTimer = Date.now();
  21049. this._delta = 0;
  21050. return;
  21051. }
  21052. var frame = this.currFrame = this.currFrame + this.scale;
  21053. var now = Date.now();
  21054. var awake = (now - this._lastTimer) > 30000;
  21055. this._delta = (now - this._lastTimer) * this.scale;
  21056. var timer = this.currTimer = this.currTimer + this._delta;
  21057. this._lastTimer = now;
  21058. var handlers = this._handlers;
  21059. this._count = 0;
  21060. for (var i = 0, n = handlers.length; i < n; i++) {
  21061. var handler = handlers[i];
  21062. if (handler.method !== null) {
  21063. var t = handler.userFrame ? frame : timer;
  21064. if (t >= handler.exeTime) {
  21065. if (handler.repeat) {
  21066. if (!handler.jumpFrame || awake) {
  21067. handler.exeTime += handler.delay;
  21068. handler.run(false);
  21069. if (t > handler.exeTime) {
  21070. handler.exeTime += Math.ceil((t - handler.exeTime) / handler.delay) * handler.delay;
  21071. }
  21072. }
  21073. else {
  21074. while (t >= handler.exeTime) {
  21075. handler.exeTime += handler.delay;
  21076. handler.run(false);
  21077. }
  21078. }
  21079. }
  21080. else {
  21081. handler.run(true);
  21082. }
  21083. }
  21084. }
  21085. else {
  21086. this._count++;
  21087. }
  21088. }
  21089. if (this._count > 30 || frame % 200 === 0)
  21090. this._clearHandlers();
  21091. }
  21092. _clearHandlers() {
  21093. var handlers = this._handlers;
  21094. for (var i = 0, n = handlers.length; i < n; i++) {
  21095. var handler = handlers[i];
  21096. if (handler.method !== null)
  21097. this._temp.push(handler);
  21098. else
  21099. this._recoverHandler(handler);
  21100. }
  21101. this._handlers = this._temp;
  21102. handlers.length = 0;
  21103. this._temp = handlers;
  21104. }
  21105. _recoverHandler(handler) {
  21106. if (this._map[handler.key] == handler)
  21107. this._map[handler.key] = null;
  21108. handler.clear();
  21109. Timer._pool.push(handler);
  21110. }
  21111. _create(useFrame, repeat, delay, caller, method, args, coverBefore) {
  21112. if (!delay) {
  21113. method.apply(caller, args);
  21114. return null;
  21115. }
  21116. if (coverBefore) {
  21117. var handler = this._getHandler(caller, method);
  21118. if (handler) {
  21119. handler.repeat = repeat;
  21120. handler.userFrame = useFrame;
  21121. handler.delay = delay;
  21122. handler.caller = caller;
  21123. handler.method = method;
  21124. handler.args = args;
  21125. handler.exeTime = delay + (useFrame ? this.currFrame : this.currTimer + Date.now() - this._lastTimer);
  21126. return handler;
  21127. }
  21128. }
  21129. handler = Timer._pool.length > 0 ? Timer._pool.pop() : new TimerHandler();
  21130. handler.repeat = repeat;
  21131. handler.userFrame = useFrame;
  21132. handler.delay = delay;
  21133. handler.caller = caller;
  21134. handler.method = method;
  21135. handler.args = args;
  21136. handler.exeTime = delay + (useFrame ? this.currFrame : this.currTimer + Date.now() - this._lastTimer);
  21137. this._indexHandler(handler);
  21138. this._handlers.push(handler);
  21139. return handler;
  21140. }
  21141. _indexHandler(handler) {
  21142. var caller = handler.caller;
  21143. var method = handler.method;
  21144. var cid = caller ? caller.$_GID || (caller.$_GID = ILaya.Utils.getGID()) : 0;
  21145. var mid = method.$_TID || (method.$_TID = (Timer._mid++) * 100000);
  21146. handler.key = cid + mid;
  21147. this._map[handler.key] = handler;
  21148. }
  21149. once(delay, caller, method, args = null, coverBefore = true) {
  21150. this._create(false, false, delay, caller, method, args, coverBefore);
  21151. }
  21152. loop(delay, caller, method, args = null, coverBefore = true, jumpFrame = false) {
  21153. var handler = this._create(false, true, delay, caller, method, args, coverBefore);
  21154. if (handler)
  21155. handler.jumpFrame = jumpFrame;
  21156. }
  21157. frameOnce(delay, caller, method, args = null, coverBefore = true) {
  21158. this._create(true, false, delay, caller, method, args, coverBefore);
  21159. }
  21160. frameLoop(delay, caller, method, args = null, coverBefore = true) {
  21161. this._create(true, true, delay, caller, method, args, coverBefore);
  21162. }
  21163. toString() {
  21164. return " handlers:" + this._handlers.length + " pool:" + Timer._pool.length;
  21165. }
  21166. clear(caller, method) {
  21167. var handler = this._getHandler(caller, method);
  21168. if (handler) {
  21169. this._map[handler.key] = null;
  21170. handler.key = 0;
  21171. handler.clear();
  21172. }
  21173. }
  21174. clearAll(caller) {
  21175. if (!caller)
  21176. return;
  21177. for (var i = 0, n = this._handlers.length; i < n; i++) {
  21178. var handler = this._handlers[i];
  21179. if (handler.caller === caller) {
  21180. this._map[handler.key] = null;
  21181. handler.key = 0;
  21182. handler.clear();
  21183. }
  21184. }
  21185. }
  21186. _getHandler(caller, method) {
  21187. var cid = caller ? caller.$_GID || (caller.$_GID = ILaya.Utils.getGID()) : 0;
  21188. var mid = method.$_TID || (method.$_TID = (Timer._mid++) * 100000);
  21189. return this._map[cid + mid];
  21190. }
  21191. callLater(caller, method, args = null) {
  21192. CallLater.I.callLater(caller, method, args);
  21193. }
  21194. runCallLater(caller, method) {
  21195. CallLater.I.runCallLater(caller, method);
  21196. }
  21197. runTimer(caller, method) {
  21198. var handler = this._getHandler(caller, method);
  21199. if (handler && handler.method != null) {
  21200. this._map[handler.key] = null;
  21201. handler.run(true);
  21202. }
  21203. }
  21204. pause() {
  21205. this.scale = 0;
  21206. }
  21207. resume() {
  21208. this.scale = 1;
  21209. }
  21210. }
  21211. Timer.gSysTimer = null;
  21212. Timer._pool = [];
  21213. Timer._mid = 1;
  21214. class TimerHandler {
  21215. clear() {
  21216. this.caller = null;
  21217. this.method = null;
  21218. this.args = null;
  21219. }
  21220. run(withClear) {
  21221. var caller = this.caller;
  21222. if (caller && caller.destroyed)
  21223. return this.clear();
  21224. var method = this.method;
  21225. var args = this.args;
  21226. withClear && this.clear();
  21227. if (method == null)
  21228. return;
  21229. args ? method.apply(caller, args) : method.call(caller);
  21230. }
  21231. }
  21232. class SkinSV extends Value2D {
  21233. constructor(type) {
  21234. super(ShaderDefines2D.SKINMESH, 0);
  21235. this.offsetX = 300;
  21236. this.offsetY = 0;
  21237. var gl = WebGLContext.mainContext;
  21238. var _vlen = 8 * CONST3D2D.BYTES_PE;
  21239. this.position = [2, gl.FLOAT, false, _vlen, 0];
  21240. this.texcoord = [2, gl.FLOAT, false, _vlen, 2 * CONST3D2D.BYTES_PE];
  21241. this.color = [4, gl.FLOAT, false, _vlen, 4 * CONST3D2D.BYTES_PE];
  21242. }
  21243. }
  21244. class PrimitiveSV extends Value2D {
  21245. constructor(args) {
  21246. super(ShaderDefines2D.PRIMITIVE, 0);
  21247. this._attribLocation = ['position', 0, 'attribColor', 1];
  21248. }
  21249. }
  21250. class TextureSV extends Value2D {
  21251. constructor(subID = 0) {
  21252. super(ShaderDefines2D.TEXTURE2D, subID);
  21253. this.strength = 0;
  21254. this.blurInfo = null;
  21255. this.colorMat = null;
  21256. this.colorAlpha = null;
  21257. this._attribLocation = ['posuv', 0, 'attribColor', 1, 'attribFlags', 2];
  21258. }
  21259. clear() {
  21260. this.texture = null;
  21261. this.shader = null;
  21262. this.defines._value = this.subID + (WebGL.shaderHighPrecision ? ShaderDefines2D.SHADERDEFINE_FSHIGHPRECISION : 0);
  21263. }
  21264. }
  21265. class InlcudeFile {
  21266. constructor(txt) {
  21267. this.codes = {};
  21268. this.funs = {};
  21269. this.curUseID = -1;
  21270. this.funnames = "";
  21271. this.script = txt;
  21272. var begin = 0, ofs, end;
  21273. while (true) {
  21274. begin = txt.indexOf("#begin", begin);
  21275. if (begin < 0)
  21276. break;
  21277. end = begin + 5;
  21278. while (true) {
  21279. end = txt.indexOf("#end", end);
  21280. if (end < 0)
  21281. break;
  21282. if (txt.charAt(end + 4) === 'i')
  21283. end += 5;
  21284. else
  21285. break;
  21286. }
  21287. if (end < 0) {
  21288. throw "add include err,no #end:" + txt;
  21289. }
  21290. ofs = txt.indexOf('\n', begin);
  21291. var words = ILaya.ShaderCompile.splitToWords(txt.substr(begin, ofs - begin), null);
  21292. if (words[1] == 'code') {
  21293. this.codes[words[2]] = txt.substr(ofs + 1, end - ofs - 1);
  21294. }
  21295. else if (words[1] == 'function') {
  21296. ofs = txt.indexOf("function", begin);
  21297. ofs += "function".length;
  21298. this.funs[words[3]] = txt.substr(ofs + 1, end - ofs - 1);
  21299. this.funnames += words[3] + ";";
  21300. }
  21301. begin = end + 1;
  21302. }
  21303. }
  21304. getWith(name = null) {
  21305. var r = name ? this.codes[name] : this.script;
  21306. if (!r) {
  21307. throw "get with error:" + name;
  21308. }
  21309. return r;
  21310. }
  21311. getFunsScript(funsdef) {
  21312. var r = "";
  21313. for (var i in this.funs) {
  21314. if (funsdef.indexOf(i + ";") >= 0) {
  21315. r += this.funs[i];
  21316. }
  21317. }
  21318. return r;
  21319. }
  21320. }
  21321. class ShaderNode {
  21322. constructor(includefiles) {
  21323. this.childs = [];
  21324. this.text = "";
  21325. this.useFuns = "";
  21326. this.z = 0;
  21327. this.includefiles = includefiles;
  21328. }
  21329. setParent(parent) {
  21330. parent.childs.push(this);
  21331. this.z = parent.z + 1;
  21332. this.parent = parent;
  21333. }
  21334. setCondition(condition, type) {
  21335. if (condition) {
  21336. this.conditionType = type;
  21337. condition = condition.replace(/(\s*$)/g, "");
  21338. this.condition = function () {
  21339. return this[condition];
  21340. };
  21341. this.condition.__condition = condition;
  21342. }
  21343. }
  21344. toscript(def, out) {
  21345. return this._toscript(def, out, ++ShaderNode.__id);
  21346. }
  21347. _toscript(def, out, id) {
  21348. if (this.childs.length < 1 && !this.text)
  21349. return out;
  21350. var outIndex = out.length;
  21351. if (this.condition) {
  21352. var ifdef = !!this.condition.call(def);
  21353. this.conditionType === ILaya.ShaderCompile.IFDEF_ELSE && (ifdef = !ifdef);
  21354. if (!ifdef)
  21355. return out;
  21356. }
  21357. this.text && out.push(this.text);
  21358. this.childs.length > 0 && this.childs.forEach(function (o, index, arr) {
  21359. o._toscript(def, out, id);
  21360. });
  21361. if (this.includefiles.length > 0 && this.useFuns.length > 0) {
  21362. var funsCode;
  21363. for (var i = 0, n = this.includefiles.length; i < n; i++) {
  21364. if (this.includefiles[i].curUseID == id) {
  21365. continue;
  21366. }
  21367. funsCode = this.includefiles[i].file.getFunsScript(this.useFuns);
  21368. if (funsCode.length > 0) {
  21369. this.includefiles[i].curUseID = id;
  21370. out[0] = funsCode + out[0];
  21371. }
  21372. }
  21373. }
  21374. return out;
  21375. }
  21376. }
  21377. ShaderNode.__id = 1;
  21378. class ShaderCompile {
  21379. constructor(vs, ps, nameMap) {
  21380. this.defs = {};
  21381. let _this = this;
  21382. function _compile(script) {
  21383. script = script.replace(ShaderCompile._clearCR, "");
  21384. var includefiles = [];
  21385. var top = new ShaderNode(includefiles);
  21386. _this._compileToTree(top, script.split('\n'), 0, includefiles, _this.defs);
  21387. return top;
  21388. }
  21389. var startTime = Date.now();
  21390. this._VS = _compile(vs);
  21391. this._PS = _compile(ps);
  21392. this._nameMap = nameMap;
  21393. if ((Date.now() - startTime) > 2)
  21394. console.log("ShaderCompile use time:" + (Date.now() - startTime) + " size:" + vs.length + "/" + ps.length);
  21395. }
  21396. static __init__() {
  21397. var gl = LayaGL.instance;
  21398. 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 };
  21399. }
  21400. static _parseOne(attributes, uniforms, words, i, word, b) {
  21401. var one = { type: ShaderCompile.shaderParamsMap[words[i + 1]], name: words[i + 2], size: isNaN(parseInt(words[i + 3])) ? 1 : parseInt(words[i + 3]) };
  21402. if (b) {
  21403. if (word == "attribute") {
  21404. attributes.push(one);
  21405. }
  21406. else {
  21407. uniforms.push(one);
  21408. }
  21409. }
  21410. if (words[i + 3] == ':') {
  21411. one.type = words[i + 4];
  21412. i += 2;
  21413. }
  21414. i += 2;
  21415. return i;
  21416. }
  21417. static addInclude(fileName, txt) {
  21418. if (!txt || txt.length === 0)
  21419. throw new Error("add shader include file err:" + fileName);
  21420. if (ShaderCompile.includes[fileName])
  21421. throw new Error("add shader include file err, has add:" + fileName);
  21422. ShaderCompile.includes[fileName] = new InlcudeFile(txt);
  21423. }
  21424. static preGetParams(vs, ps) {
  21425. var text = [vs, ps];
  21426. var result = {};
  21427. var attributes = [];
  21428. var uniforms = [];
  21429. var definesInfo = {};
  21430. var definesName = [];
  21431. result.attributes = attributes;
  21432. result.uniforms = uniforms;
  21433. result.defines = definesInfo;
  21434. var i, n;
  21435. for (var s = 0; s < 2; s++) {
  21436. text[s] = text[s].replace(ShaderCompile._removeAnnotation, "");
  21437. var words = text[s].match(ShaderCompile._reg);
  21438. var tempelse;
  21439. for (i = 0, n = words.length; i < n; i++) {
  21440. var word = words[i];
  21441. if (word != "attribute" && word != "uniform") {
  21442. if (word == "#define") {
  21443. word = words[++i];
  21444. definesName[word] = 1;
  21445. continue;
  21446. }
  21447. else if (word == "#ifdef") {
  21448. tempelse = words[++i];
  21449. var def = definesInfo[tempelse] = definesInfo[tempelse] || [];
  21450. for (i++; i < n; i++) {
  21451. word = words[i];
  21452. if (word != "attribute" && word != "uniform") {
  21453. if (word == "#else") {
  21454. for (i++; i < n; i++) {
  21455. word = words[i];
  21456. if (word != "attribute" && word != "uniform") {
  21457. if (word == "#endif") {
  21458. break;
  21459. }
  21460. continue;
  21461. }
  21462. i = ShaderCompile._parseOne(attributes, uniforms, words, i, word, !definesName[tempelse]);
  21463. }
  21464. }
  21465. continue;
  21466. }
  21467. i = ShaderCompile._parseOne(attributes, uniforms, words, i, word, definesName[tempelse]);
  21468. }
  21469. }
  21470. continue;
  21471. }
  21472. i = ShaderCompile._parseOne(attributes, uniforms, words, i, word, true);
  21473. }
  21474. }
  21475. return result;
  21476. }
  21477. static splitToWords(str, block) {
  21478. var out = [];
  21479. var c;
  21480. var ofs = -1;
  21481. var word;
  21482. for (var i = 0, n = str.length; i < n; i++) {
  21483. c = str.charAt(i);
  21484. if (" \t=+-*/&%!<>()'\",;".indexOf(c) >= 0) {
  21485. if (ofs >= 0 && (i - ofs) > 1) {
  21486. word = str.substr(ofs, i - ofs);
  21487. out.push(word);
  21488. }
  21489. if (c == '"' || c == "'") {
  21490. var ofs2 = str.indexOf(c, i + 1);
  21491. if (ofs2 < 0) {
  21492. throw "Sharder err:" + str;
  21493. }
  21494. out.push(str.substr(i + 1, ofs2 - i - 1));
  21495. i = ofs2;
  21496. ofs = -1;
  21497. continue;
  21498. }
  21499. if (c == '(' && block && out.length > 0) {
  21500. word = out[out.length - 1] + ";";
  21501. if ("vec4;main;".indexOf(word) < 0)
  21502. block.useFuns += word;
  21503. }
  21504. ofs = -1;
  21505. continue;
  21506. }
  21507. if (ofs < 0)
  21508. ofs = i;
  21509. }
  21510. if (ofs < n && (n - ofs) > 1) {
  21511. word = str.substr(ofs, n - ofs);
  21512. out.push(word);
  21513. }
  21514. return out;
  21515. }
  21516. _compileToTree(parent, lines, start, includefiles, defs) {
  21517. var node, preNode;
  21518. var text, name, fname;
  21519. var ofs, words, noUseNode;
  21520. var i, n, j;
  21521. for (i = start; i < lines.length; i++) {
  21522. text = lines[i];
  21523. if (text.length < 1)
  21524. continue;
  21525. ofs = text.indexOf("//");
  21526. if (ofs === 0)
  21527. continue;
  21528. if (ofs >= 0)
  21529. text = text.substr(0, ofs);
  21530. node = noUseNode || new ShaderNode(includefiles);
  21531. noUseNode = null;
  21532. node.text = text;
  21533. node.noCompile = true;
  21534. if ((ofs = text.indexOf("#")) >= 0) {
  21535. name = "#";
  21536. for (j = ofs + 1, n = text.length; j < n; j++) {
  21537. var c = text.charAt(j);
  21538. if (c === ' ' || c === '\t' || c === '?')
  21539. break;
  21540. name += c;
  21541. }
  21542. node.name = name;
  21543. switch (name) {
  21544. case "#ifdef":
  21545. case "#ifndef":
  21546. node.src = text;
  21547. node.noCompile = text.match(/[!&|()=<>]/) != null;
  21548. if (!node.noCompile) {
  21549. words = text.replace(/^\s*/, '').split(/\s+/);
  21550. node.setCondition(words[1], name === "#ifdef" ? ShaderCompile.IFDEF_YES : ShaderCompile.IFDEF_ELSE);
  21551. node.text = "//" + node.text;
  21552. }
  21553. else {
  21554. console.log("function():Boolean{return " + text.substr(ofs + node.name.length) + "}");
  21555. }
  21556. node.setParent(parent);
  21557. parent = node;
  21558. if (defs) {
  21559. words = text.substr(j).split(ShaderCompile._splitToWordExps3);
  21560. for (j = 0; j < words.length; j++) {
  21561. text = words[j];
  21562. text.length && (defs[text] = true);
  21563. }
  21564. }
  21565. continue;
  21566. case "#if":
  21567. node.src = text;
  21568. node.noCompile = true;
  21569. node.setParent(parent);
  21570. parent = node;
  21571. if (defs) {
  21572. words = text.substr(j).split(ShaderCompile._splitToWordExps3);
  21573. for (j = 0; j < words.length; j++) {
  21574. text = words[j];
  21575. text.length && text != "defined" && (defs[text] = true);
  21576. }
  21577. }
  21578. continue;
  21579. case "#else":
  21580. node.src = text;
  21581. parent = parent.parent;
  21582. preNode = parent.childs[parent.childs.length - 1];
  21583. node.noCompile = preNode.noCompile;
  21584. if (!node.noCompile) {
  21585. node.condition = preNode.condition;
  21586. node.conditionType = preNode.conditionType == ShaderCompile.IFDEF_YES ? ShaderCompile.IFDEF_ELSE : ShaderCompile.IFDEF_YES;
  21587. node.text = "//" + node.text + " " + preNode.text + " " + node.conditionType;
  21588. }
  21589. node.setParent(parent);
  21590. parent = node;
  21591. continue;
  21592. case "#endif":
  21593. parent = parent.parent;
  21594. preNode = parent.childs[parent.childs.length - 1];
  21595. node.noCompile = preNode.noCompile;
  21596. if (!node.noCompile) {
  21597. node.text = "//" + node.text;
  21598. }
  21599. node.setParent(parent);
  21600. continue;
  21601. case "#include":
  21602. words = ShaderCompile.splitToWords(text, null);
  21603. var inlcudeFile = ShaderCompile.includes[words[1]];
  21604. if (!inlcudeFile) {
  21605. throw "ShaderCompile error no this include file:" + words[1];
  21606. }
  21607. if ((ofs = words[0].indexOf("?")) < 0) {
  21608. node.setParent(parent);
  21609. text = inlcudeFile.getWith(words[2] == 'with' ? words[3] : null);
  21610. this._compileToTree(node, text.split('\n'), 0, includefiles, defs);
  21611. node.text = "";
  21612. continue;
  21613. }
  21614. node.setCondition(words[0].substr(ofs + 1), ShaderCompile.IFDEF_YES);
  21615. node.text = inlcudeFile.getWith(words[2] == 'with' ? words[3] : null);
  21616. break;
  21617. case "#import":
  21618. words = ShaderCompile.splitToWords(text, null);
  21619. fname = words[1];
  21620. includefiles.push({ node: node, file: ShaderCompile.includes[fname], ofs: node.text.length });
  21621. continue;
  21622. }
  21623. }
  21624. else {
  21625. preNode = parent.childs[parent.childs.length - 1];
  21626. if (preNode && !preNode.name) {
  21627. includefiles.length > 0 && ShaderCompile.splitToWords(text, preNode);
  21628. noUseNode = node;
  21629. preNode.text += "\n" + text;
  21630. continue;
  21631. }
  21632. includefiles.length > 0 && ShaderCompile.splitToWords(text, node);
  21633. }
  21634. node.setParent(parent);
  21635. }
  21636. }
  21637. createShader(define, shaderName, createShader, bindAttrib) {
  21638. var defMap = {};
  21639. var defineStr = "";
  21640. if (define) {
  21641. for (var i in define) {
  21642. defineStr += "#define " + i + "\n";
  21643. defMap[i] = true;
  21644. }
  21645. }
  21646. var vs = this._VS.toscript(defMap, []);
  21647. var ps = this._PS.toscript(defMap, []);
  21648. return (createShader || Shader.create)(defineStr + vs.join('\n'), defineStr + ps.join('\n'), shaderName, this._nameMap, bindAttrib);
  21649. }
  21650. }
  21651. ShaderCompile.IFDEF_NO = 0;
  21652. ShaderCompile.IFDEF_YES = 1;
  21653. ShaderCompile.IFDEF_ELSE = 2;
  21654. ShaderCompile.IFDEF_PARENT = 3;
  21655. ShaderCompile._removeAnnotation = new RegExp("(/\\*([^*]|[\\r\\\n]|(\\*+([^*/]|[\\r\\n])))*\\*+/)|(//.*)", "g");
  21656. ShaderCompile._reg = new RegExp("(\".*\")|('.*')|([#\\w\\*-\\.+/()=<>{}\\\\]+)|([,;:\\\\])", "g");
  21657. ShaderCompile._splitToWordExps = new RegExp("[(\".*\")]+|[('.*')]+|([ \\t=\\+\\-*/&%!<>!%\(\),;])", "g");
  21658. ShaderCompile.includes = {};
  21659. ShaderCompile._clearCR = new RegExp("\r", "g");
  21660. ShaderCompile._splitToWordExps3 = new RegExp("[ \\t=\\+\\-*/&%!<>!%\(\),;\\|]", "g");
  21661. class WorkerLoader extends EventDispatcher {
  21662. constructor() {
  21663. super();
  21664. this.worker = new Worker(WorkerLoader.workerPath);
  21665. let me = this;
  21666. this.worker.onmessage = function (evt) {
  21667. me.workerMessage(evt.data);
  21668. };
  21669. }
  21670. static __init__() {
  21671. if (WorkerLoader._preLoadFun != null)
  21672. return false;
  21673. if (!Worker)
  21674. return false;
  21675. WorkerLoader._preLoadFun = Loader["prototype"]["_loadImage"];
  21676. Loader["prototype"]["_loadImage"] = WorkerLoader["prototype"]["_loadImage"];
  21677. if (!WorkerLoader.I)
  21678. WorkerLoader.I = new WorkerLoader();
  21679. return true;
  21680. }
  21681. static workerSupported() {
  21682. return Worker ? true : false;
  21683. }
  21684. static enableWorkerLoader() {
  21685. if (!WorkerLoader._tryEnabled) {
  21686. WorkerLoader.enable = true;
  21687. WorkerLoader._tryEnabled = true;
  21688. }
  21689. }
  21690. static set enable(value) {
  21691. if (WorkerLoader._enable != value) {
  21692. WorkerLoader._enable = value;
  21693. if (value && WorkerLoader._preLoadFun == null)
  21694. WorkerLoader._enable = WorkerLoader.__init__();
  21695. }
  21696. }
  21697. static get enable() {
  21698. return WorkerLoader._enable;
  21699. }
  21700. workerMessage(data) {
  21701. if (data) {
  21702. switch (data.type) {
  21703. case "Image":
  21704. this.imageLoaded(data);
  21705. break;
  21706. case "Disable":
  21707. WorkerLoader.enable = false;
  21708. break;
  21709. }
  21710. }
  21711. }
  21712. imageLoaded(data) {
  21713. if (!data.dataType || data.dataType != "imageBitmap") {
  21714. this.event(data.url, null);
  21715. return;
  21716. }
  21717. var imageData = data.imageBitmap;
  21718. var tex = new Texture2D();
  21719. tex.loadImageSource(imageData);
  21720. console.log("load:", data.url);
  21721. this.event(data.url, tex);
  21722. }
  21723. loadImage(url) {
  21724. this.worker.postMessage(url);
  21725. }
  21726. _loadImage(url) {
  21727. var _this = this;
  21728. if (!this._useWorkerLoader || !WorkerLoader._enable) {
  21729. WorkerLoader._preLoadFun.call(_this, url);
  21730. return;
  21731. }
  21732. url = URL.formatURL(url);
  21733. function clear() {
  21734. WorkerLoader.I.off(url, _this, onload);
  21735. }
  21736. var onload = function (image) {
  21737. clear();
  21738. if (image) {
  21739. _this["onLoaded"](image);
  21740. }
  21741. else {
  21742. WorkerLoader._preLoadFun.call(_this, url);
  21743. }
  21744. };
  21745. WorkerLoader.I.on(url, _this, onload);
  21746. WorkerLoader.I.loadImage(url);
  21747. }
  21748. }
  21749. WorkerLoader.workerPath = "libs/workerloader.js";
  21750. WorkerLoader._enable = false;
  21751. WorkerLoader._tryEnabled = false;
  21752. class Mouse {
  21753. static set cursor(cursorStr) {
  21754. Mouse._style.cursor = cursorStr;
  21755. }
  21756. static get cursor() {
  21757. return Mouse._style.cursor;
  21758. }
  21759. static __init__() {
  21760. }
  21761. static hide() {
  21762. if (Mouse.cursor != "none") {
  21763. Mouse._preCursor = Mouse.cursor;
  21764. Mouse.cursor = "none";
  21765. }
  21766. }
  21767. static show() {
  21768. if (Mouse.cursor == "none") {
  21769. if (Mouse._preCursor) {
  21770. Mouse.cursor = Mouse._preCursor;
  21771. }
  21772. else {
  21773. Mouse.cursor = "auto";
  21774. }
  21775. }
  21776. }
  21777. }
  21778. class MeshParticle2D extends Mesh2D {
  21779. constructor(maxNum) {
  21780. super(MeshParticle2D.const_stride, maxNum * 4 * MeshParticle2D.const_stride, 4);
  21781. this.canReuse = true;
  21782. this.setAttributes(MeshParticle2D._fixattriInfo);
  21783. this.createQuadIB(maxNum);
  21784. this._quadNum = maxNum;
  21785. }
  21786. static __init__() {
  21787. var gl = LayaGL.instance;
  21788. MeshParticle2D._fixattriInfo = [gl.FLOAT, 4, 0,
  21789. gl.FLOAT, 3, 16,
  21790. gl.FLOAT, 3, 28,
  21791. gl.FLOAT, 4, 40,
  21792. gl.FLOAT, 4, 56,
  21793. gl.FLOAT, 3, 72,
  21794. gl.FLOAT, 2, 84,
  21795. gl.FLOAT, 4, 92,
  21796. gl.FLOAT, 1, 108,
  21797. gl.FLOAT, 1, 112];
  21798. }
  21799. setMaxParticleNum(maxNum) {
  21800. this._vb._resizeBuffer(maxNum * 4 * MeshParticle2D.const_stride, false);
  21801. this.createQuadIB(maxNum);
  21802. }
  21803. static getAMesh(maxNum) {
  21804. if (MeshParticle2D._POOL.length) {
  21805. var ret = MeshParticle2D._POOL.pop();
  21806. ret.setMaxParticleNum(maxNum);
  21807. return ret;
  21808. }
  21809. return new MeshParticle2D(maxNum);
  21810. }
  21811. releaseMesh() {
  21812. this._vb.setByteLength(0);
  21813. this.vertNum = 0;
  21814. this.indexNum = 0;
  21815. MeshParticle2D._POOL.push(this);
  21816. }
  21817. destroy() {
  21818. this._ib.destroy();
  21819. this._vb.destroy();
  21820. this._vb.deleteBuffer();
  21821. }
  21822. }
  21823. MeshParticle2D.const_stride = 116;
  21824. MeshParticle2D._POOL = [];
  21825. class HTMLImage extends Bitmap {
  21826. }
  21827. HTMLImage.create = function (width, height, format) {
  21828. var tex = new Texture2D(width, height, format, false, false);
  21829. tex.wrapModeU = BaseTexture.WARPMODE_CLAMP;
  21830. tex.wrapModeV = BaseTexture.WARPMODE_CLAMP;
  21831. return tex;
  21832. };
  21833. class Laya {
  21834. static __init(_classs) {
  21835. _classs.forEach(function (o) { o.__init$ && o.__init$(); });
  21836. }
  21837. static init(width, height, ...plugins) {
  21838. if (Laya._isinit)
  21839. return;
  21840. Laya._isinit = true;
  21841. ArrayBuffer.prototype.slice || (ArrayBuffer.prototype.slice = Laya._arrayBufferSlice);
  21842. Browser.__init__();
  21843. var mainCanv = Browser.mainCanvas = new HTMLCanvas(true);
  21844. var style = mainCanv.source.style;
  21845. style.position = 'absolute';
  21846. style.top = style.left = "0px";
  21847. style.background = "#000000";
  21848. if (!Browser.onKGMiniGame && !Browser.onAlipayMiniGame) {
  21849. Browser.container.appendChild(mainCanv.source);
  21850. }
  21851. Browser.canvas = new HTMLCanvas(true);
  21852. Browser.context = Browser.canvas.getContext('2d');
  21853. Browser.supportWebAudio = SoundManager.__init__();
  21854. Browser.supportLocalStorage = LocalStorage.__init__();
  21855. Laya.systemTimer = new Timer(false);
  21856. exports.systemTimer = Timer.gSysTimer = Laya.systemTimer;
  21857. Laya.startTimer = new Timer(false);
  21858. Laya.physicsTimer = new Timer(false);
  21859. Laya.updateTimer = new Timer(false);
  21860. Laya.lateTimer = new Timer(false);
  21861. Laya.timer = new Timer(false);
  21862. exports.startTimer = ILaya.startTimer = Laya.startTimer;
  21863. exports.lateTimer = ILaya.lateTimer = Laya.lateTimer;
  21864. exports.updateTimer = ILaya.updateTimer = Laya.updateTimer;
  21865. ILaya.systemTimer = Laya.systemTimer;
  21866. exports.timer = ILaya.timer = Laya.timer;
  21867. exports.physicsTimer = ILaya.physicsTimer = Laya.physicsTimer;
  21868. Laya.loader = new LoaderManager();
  21869. ILaya.Laya = Laya;
  21870. exports.loader = ILaya.loader = Laya.loader;
  21871. WeakObject.__init__();
  21872. SceneUtils.__init();
  21873. Mouse.__init__();
  21874. WebGL.inner_enable();
  21875. for (var i = 0, n = plugins.length; i < n; i++) {
  21876. if (plugins[i] && plugins[i].enable) {
  21877. plugins[i].enable();
  21878. }
  21879. }
  21880. if (ILaya.Render.isConchApp) {
  21881. Laya.enableNative();
  21882. }
  21883. Laya.enableWebGLPlus();
  21884. CacheManger.beginCheck();
  21885. exports.stage = Laya.stage = new Stage();
  21886. ILaya.stage = Laya.stage;
  21887. Utils.gStage = Laya.stage;
  21888. URL.rootPath = URL._basePath = Laya._getUrlPath();
  21889. MeshQuadTexture.__int__();
  21890. MeshVG.__init__();
  21891. MeshTexture.__init__();
  21892. Laya.render = new Render(0, 0, Browser.mainCanvas);
  21893. exports.render = Laya.render;
  21894. Laya.stage.size(width, height);
  21895. window.stage = Laya.stage;
  21896. WebGLContext.__init__();
  21897. MeshParticle2D.__init__();
  21898. ShaderCompile.__init__();
  21899. RenderSprite.__init__();
  21900. KeyBoardManager.__init__();
  21901. MouseManager.instance.__init__(Laya.stage, Render.canvas);
  21902. Input.__init__();
  21903. SoundManager.autoStopMusic = true;
  21904. Stat._StatRender = new StatUI();
  21905. Value2D._initone(ShaderDefines2D.TEXTURE2D, TextureSV);
  21906. Value2D._initone(ShaderDefines2D.TEXTURE2D | ShaderDefines2D.FILTERGLOW, TextureSV);
  21907. Value2D._initone(ShaderDefines2D.PRIMITIVE, PrimitiveSV);
  21908. Value2D._initone(ShaderDefines2D.SKINMESH, SkinSV);
  21909. return Render.canvas;
  21910. }
  21911. static _getUrlPath() {
  21912. var location = Browser.window.location;
  21913. var pathName = location.pathname;
  21914. pathName = pathName.charAt(2) == ':' ? pathName.substring(1) : pathName;
  21915. return URL.getPath(location.protocol == "file:" ? pathName : location.protocol + "//" + location.host + location.pathname);
  21916. }
  21917. static _arrayBufferSlice(start, end) {
  21918. var arr = this;
  21919. var arrU8List = new Uint8Array(arr, start, end - start);
  21920. var newU8List = new Uint8Array(arrU8List.length);
  21921. newU8List.set(arrU8List);
  21922. return newU8List.buffer;
  21923. }
  21924. static set alertGlobalError(value) {
  21925. var erralert = 0;
  21926. if (value) {
  21927. Browser.window.onerror = function (msg, url, line, column, detail) {
  21928. if (erralert++ < 5 && detail)
  21929. this.alert("出错啦,请把此信息截图给研发商\n" + msg + "\n" + detail.stack);
  21930. };
  21931. }
  21932. else {
  21933. Browser.window.onerror = null;
  21934. }
  21935. }
  21936. static _runScript(script) {
  21937. return Browser.window[Laya._evcode](script);
  21938. }
  21939. static enableDebugPanel(debugJsPath = "libs/laya.debugtool.js") {
  21940. if (!Laya["DebugPanel"]) {
  21941. var script = Browser.createElement("script");
  21942. script.onload = function () {
  21943. Laya["DebugPanel"].enable();
  21944. };
  21945. script.src = debugJsPath;
  21946. Browser.document.body.appendChild(script);
  21947. }
  21948. else {
  21949. Laya["DebugPanel"].enable();
  21950. }
  21951. }
  21952. static enableWebGLPlus() {
  21953. WebGLContext.__init_native();
  21954. }
  21955. static enableNative() {
  21956. if (Laya.isNativeRender_enable)
  21957. return;
  21958. Laya.isNativeRender_enable = true;
  21959. Shader.prototype.uploadTexture2D = function (value) {
  21960. var gl = LayaGL.instance;
  21961. gl.bindTexture(gl.TEXTURE_2D, value);
  21962. };
  21963. RenderState2D.width = Browser.window.innerWidth;
  21964. RenderState2D.height = Browser.window.innerHeight;
  21965. Browser.measureText = function (txt, font) {
  21966. window["conchTextCanvas"].font = font;
  21967. return window["conchTextCanvas"].measureText(txt);
  21968. };
  21969. Stage.clear = function (color) {
  21970. Context.set2DRenderConfig();
  21971. var c = ColorUtils.create(color).arrColor;
  21972. var gl = LayaGL.instance;
  21973. if (c)
  21974. gl.clearColor(c[0], c[1], c[2], c[3]);
  21975. gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
  21976. RenderState2D.clear();
  21977. };
  21978. Sprite.drawToCanvas = Sprite.drawToTexture = function (sprite, _renderType, canvasWidth, canvasHeight, offsetX, offsetY) {
  21979. offsetX -= sprite.x;
  21980. offsetY -= sprite.y;
  21981. offsetX |= 0;
  21982. offsetY |= 0;
  21983. canvasWidth |= 0;
  21984. canvasHeight |= 0;
  21985. var canv = new HTMLCanvas(false);
  21986. var ctx = canv.getContext('2d');
  21987. canv.size(canvasWidth, canvasHeight);
  21988. ctx.asBitmap = true;
  21989. ctx._targets.start();
  21990. RenderSprite.renders[_renderType]._fun(sprite, ctx, offsetX, offsetY);
  21991. ctx.flush();
  21992. ctx._targets.end();
  21993. ctx._targets.restore();
  21994. return canv;
  21995. };
  21996. Object["defineProperty"](RenderTexture2D.prototype, "uv", {
  21997. "get": function () {
  21998. return this._uv;
  21999. },
  22000. "set": function (v) {
  22001. this._uv = v;
  22002. }
  22003. });
  22004. HTMLCanvas.prototype.getTexture = function () {
  22005. if (!this._texture) {
  22006. this._texture = this.context._targets;
  22007. this._texture.uv = RenderTexture2D.flipyuv;
  22008. this._texture.bitmap = this._texture;
  22009. }
  22010. return this._texture;
  22011. };
  22012. }
  22013. }
  22014. Laya.stage = null;
  22015. Laya.systemTimer = null;
  22016. Laya.startTimer = null;
  22017. Laya.physicsTimer = null;
  22018. Laya.updateTimer = null;
  22019. Laya.lateTimer = null;
  22020. Laya.timer = null;
  22021. Laya.loader = null;
  22022. Laya.version = "2.2.0";
  22023. Laya._isinit = false;
  22024. Laya.isWXOpenDataContext = false;
  22025. Laya.isWXPosMsg = false;
  22026. Laya.__classmap = null;
  22027. Laya.Config = Config;
  22028. Laya.TextRender = TextRender;
  22029. Laya.EventDispatcher = EventDispatcher;
  22030. Laya.SoundChannel = SoundChannel;
  22031. Laya.Stage = Stage;
  22032. Laya.Render = Render;
  22033. Laya.Browser = Browser;
  22034. Laya.Sprite = Sprite;
  22035. Laya.Node = Node;
  22036. Laya.Context = Context;
  22037. Laya.WebGL = WebGL;
  22038. Laya.Handler = Handler;
  22039. Laya.RunDriver = RunDriver;
  22040. Laya.Utils = Utils;
  22041. Laya.Input = Input;
  22042. Laya.Loader = Loader;
  22043. Laya.LocalStorage = LocalStorage;
  22044. Laya.SoundManager = SoundManager;
  22045. Laya.URL = URL;
  22046. Laya.Event = Event;
  22047. Laya.Matrix = Matrix;
  22048. Laya.HTMLImage = HTMLImage;
  22049. Laya.Laya = Laya;
  22050. Laya._evcode = "eva" + "l";
  22051. Laya.isNativeRender_enable = false;
  22052. Laya.__classmap = ILaya.__classMap;
  22053. ILaya.Timer = Timer;
  22054. ILaya.Dragging = Dragging;
  22055. ILaya.GraphicsBounds = GraphicsBounds;
  22056. ILaya.Sprite = Sprite;
  22057. ILaya.TextRender = TextRender;
  22058. ILaya.Loader = Loader;
  22059. ILaya.TTFLoader = TTFLoader;
  22060. ILaya.WebAudioSound = WebAudioSound;
  22061. ILaya.SoundManager = SoundManager;
  22062. ILaya.ShaderCompile = ShaderCompile;
  22063. ILaya.ClassUtils = ClassUtils;
  22064. ILaya.SceneUtils = SceneUtils;
  22065. ILaya.Context = Context;
  22066. ILaya.Render = Render;
  22067. ILaya.MouseManager = MouseManager;
  22068. ILaya.Text = Text;
  22069. ILaya.Browser = Browser;
  22070. ILaya.WebGL = WebGL;
  22071. ILaya.AudioSound = AudioSound;
  22072. ILaya.Pool = Pool;
  22073. ILaya.Utils = Utils;
  22074. ILaya.Graphics = Graphics;
  22075. ILaya.Submit = Submit;
  22076. ILaya.Stage = Stage;
  22077. ILaya.Resource = Resource;
  22078. ILaya.WorkerLoader = WorkerLoader;
  22079. var libs = window._layalibs;
  22080. if (libs) {
  22081. libs.sort(function (a, b) {
  22082. return a.i - b.i;
  22083. });
  22084. for (var j = 0; j < libs.length; j++) {
  22085. libs[j].f(window, window.document, Laya);
  22086. }
  22087. }
  22088. let win = window;
  22089. if (win.Laya) {
  22090. win.Laya.Laya = Laya;
  22091. Object.assign(win.Laya, Laya);
  22092. }
  22093. else
  22094. win.Laya = Laya;
  22095. var __init = Laya.__init;
  22096. var init = Laya.init;
  22097. var version = Laya.version;
  22098. var isWXOpenDataContext;
  22099. var isWXPosMsg;
  22100. var alertGlobalError = Laya.alertGlobalError;
  22101. var enableDebugPanel = Laya.enableDebugPanel;
  22102. function _static(_class, def) {
  22103. for (var i = 0, sz = def.length; i < sz; i += 2) {
  22104. if (def[i] == 'length')
  22105. _class.length = def[i + 1].call(_class);
  22106. else {
  22107. function tmp() {
  22108. var name = def[i];
  22109. var getfn = def[i + 1];
  22110. Object.defineProperty(_class, name, {
  22111. get: function () { delete this[name]; return this[name] = getfn.call(this); },
  22112. set: function (v) { delete this[name]; this[name] = v; }, enumerable: true, configurable: true
  22113. });
  22114. }
  22115. tmp();
  22116. }
  22117. }
  22118. }
  22119. class CommonScript extends Component {
  22120. get isSingleton() {
  22121. return false;
  22122. }
  22123. constructor() {
  22124. super();
  22125. }
  22126. onAwake() {
  22127. }
  22128. onEnable() {
  22129. }
  22130. onStart() {
  22131. }
  22132. onUpdate() {
  22133. }
  22134. onLateUpdate() {
  22135. }
  22136. onDisable() {
  22137. }
  22138. onDestroy() {
  22139. }
  22140. }
  22141. class Script extends Component {
  22142. get isSingleton() {
  22143. return false;
  22144. }
  22145. _onAwake() {
  22146. this.onAwake();
  22147. if (this.onStart !== Script.prototype.onStart) {
  22148. ILaya.startTimer.callLater(this, this.onStart);
  22149. }
  22150. }
  22151. _onEnable() {
  22152. var proto = Script.prototype;
  22153. if (this.onTriggerEnter !== proto.onTriggerEnter) {
  22154. this.owner.on(Event.TRIGGER_ENTER, this, this.onTriggerEnter);
  22155. }
  22156. if (this.onTriggerStay !== proto.onTriggerStay) {
  22157. this.owner.on(Event.TRIGGER_STAY, this, this.onTriggerStay);
  22158. }
  22159. if (this.onTriggerExit !== proto.onTriggerExit) {
  22160. this.owner.on(Event.TRIGGER_EXIT, this, this.onTriggerExit);
  22161. }
  22162. if (this.onMouseDown !== proto.onMouseDown) {
  22163. this.owner.on(Event.MOUSE_DOWN, this, this.onMouseDown);
  22164. }
  22165. if (this.onMouseUp !== proto.onMouseUp) {
  22166. this.owner.on(Event.MOUSE_UP, this, this.onMouseUp);
  22167. }
  22168. if (this.onClick !== proto.onClick) {
  22169. this.owner.on(Event.CLICK, this, this.onClick);
  22170. }
  22171. if (this.onStageMouseDown !== proto.onStageMouseDown) {
  22172. ILaya.stage.on(Event.MOUSE_DOWN, this, this.onStageMouseDown);
  22173. }
  22174. if (this.onStageMouseUp !== proto.onStageMouseUp) {
  22175. ILaya.stage.on(Event.MOUSE_UP, this, this.onStageMouseUp);
  22176. }
  22177. if (this.onStageClick !== proto.onStageClick) {
  22178. ILaya.stage.on(Event.CLICK, this, this.onStageClick);
  22179. }
  22180. if (this.onStageMouseMove !== proto.onStageMouseMove) {
  22181. ILaya.stage.on(Event.MOUSE_MOVE, this, this.onStageMouseMove);
  22182. }
  22183. if (this.onDoubleClick !== proto.onDoubleClick) {
  22184. this.owner.on(Event.DOUBLE_CLICK, this, this.onDoubleClick);
  22185. }
  22186. if (this.onRightClick !== proto.onRightClick) {
  22187. this.owner.on(Event.RIGHT_CLICK, this, this.onRightClick);
  22188. }
  22189. if (this.onMouseMove !== proto.onMouseMove) {
  22190. this.owner.on(Event.MOUSE_MOVE, this, this.onMouseMove);
  22191. }
  22192. if (this.onMouseOver !== proto.onMouseOver) {
  22193. this.owner.on(Event.MOUSE_OVER, this, this.onMouseOver);
  22194. }
  22195. if (this.onMouseOut !== proto.onMouseOut) {
  22196. this.owner.on(Event.MOUSE_OUT, this, this.onMouseOut);
  22197. }
  22198. if (this.onKeyDown !== proto.onKeyDown) {
  22199. ILaya.stage.on(Event.KEY_DOWN, this, this.onKeyDown);
  22200. }
  22201. if (this.onKeyPress !== proto.onKeyPress) {
  22202. ILaya.stage.on(Event.KEY_PRESS, this, this.onKeyPress);
  22203. }
  22204. if (this.onKeyUp !== proto.onKeyUp) {
  22205. ILaya.stage.on(Event.KEY_UP, this, this.onKeyUp);
  22206. }
  22207. if (this.onUpdate !== proto.onUpdate) {
  22208. ILaya.updateTimer.frameLoop(1, this, this.onUpdate);
  22209. }
  22210. if (this.onLateUpdate !== proto.onLateUpdate) {
  22211. ILaya.lateTimer.frameLoop(1, this, this.onLateUpdate);
  22212. }
  22213. if (this.onPreRender !== proto.onPreRender) {
  22214. ILaya.lateTimer.frameLoop(1, this, this.onPreRender);
  22215. }
  22216. }
  22217. _onDisable() {
  22218. this.owner.offAllCaller(this);
  22219. ILaya.stage.offAllCaller(this);
  22220. ILaya.startTimer.clearAll(this);
  22221. ILaya.updateTimer.clearAll(this);
  22222. ILaya.lateTimer.clearAll(this);
  22223. }
  22224. _isScript() {
  22225. return true;
  22226. }
  22227. _onDestroy() {
  22228. this.onDestroy();
  22229. }
  22230. onAwake() {
  22231. }
  22232. onEnable() {
  22233. }
  22234. onStart() {
  22235. }
  22236. onTriggerEnter(other, self, contact) {
  22237. }
  22238. onTriggerStay(other, self, contact) {
  22239. }
  22240. onTriggerExit(other, self, contact) {
  22241. }
  22242. onMouseDown(e) {
  22243. }
  22244. onMouseUp(e) {
  22245. }
  22246. onClick(e) {
  22247. }
  22248. onStageMouseDown(e) {
  22249. }
  22250. onStageMouseUp(e) {
  22251. }
  22252. onStageClick(e) {
  22253. }
  22254. onStageMouseMove(e) {
  22255. }
  22256. onDoubleClick(e) {
  22257. }
  22258. onRightClick(e) {
  22259. }
  22260. onMouseMove(e) {
  22261. }
  22262. onMouseOver(e) {
  22263. }
  22264. onMouseOut(e) {
  22265. }
  22266. onKeyDown(e) {
  22267. }
  22268. onKeyPress(e) {
  22269. }
  22270. onKeyUp(e) {
  22271. }
  22272. onUpdate() {
  22273. }
  22274. onLateUpdate() {
  22275. }
  22276. onPreRender() {
  22277. }
  22278. onPostRender() {
  22279. }
  22280. onDisable() {
  22281. }
  22282. onDestroy() {
  22283. }
  22284. }
  22285. class GraphicAnimation extends FrameAnimation {
  22286. constructor() {
  22287. super(...arguments);
  22288. this._nodeIDAniDic = {};
  22289. }
  22290. _parseNodeList(uiView) {
  22291. if (!this._nodeList)
  22292. this._nodeList = [];
  22293. this._nodeDefaultProps[uiView.compId] = uiView.props;
  22294. if (uiView.compId)
  22295. this._nodeList.push(uiView.compId);
  22296. var childs = uiView.child;
  22297. if (childs) {
  22298. var i, len = childs.length;
  22299. for (i = 0; i < len; i++) {
  22300. this._parseNodeList(childs[i]);
  22301. }
  22302. }
  22303. }
  22304. _calGraphicData(aniData) {
  22305. this._setUp(null, aniData);
  22306. this._createGraphicData();
  22307. if (this._nodeIDAniDic) {
  22308. var key;
  22309. for (key in this._nodeIDAniDic) {
  22310. this._nodeIDAniDic[key] = null;
  22311. }
  22312. }
  22313. }
  22314. _createGraphicData() {
  22315. var gList = [];
  22316. var i, len = this.count;
  22317. var animationDataNew = this._usedFrames;
  22318. if (!animationDataNew)
  22319. animationDataNew = [];
  22320. var preGraphic;
  22321. for (i = 0; i < len; i++) {
  22322. if (animationDataNew[i] || !preGraphic) {
  22323. preGraphic = this._createFrameGraphic(i);
  22324. }
  22325. gList.push(preGraphic);
  22326. }
  22327. this._gList = gList;
  22328. }
  22329. _createFrameGraphic(frame) {
  22330. var g = new Graphics();
  22331. if (!GraphicAnimation._rootMatrix)
  22332. GraphicAnimation._rootMatrix = new Matrix();
  22333. this._updateNodeGraphic(this._rootNode, frame, GraphicAnimation._rootMatrix, g);
  22334. return g;
  22335. }
  22336. _updateNodeGraphic(node, frame, parentTransfrom, g, alpha = 1) {
  22337. var tNodeG;
  22338. tNodeG = this._nodeGDic[node.compId] = this._getNodeGraphicData(node.compId, frame, this._nodeGDic[node.compId]);
  22339. if (!tNodeG.resultTransform)
  22340. tNodeG.resultTransform = new Matrix();
  22341. var tResultTransform;
  22342. tResultTransform = tNodeG.resultTransform;
  22343. Matrix.mul(tNodeG.transform, parentTransfrom, tResultTransform);
  22344. var tTex;
  22345. var tGraphicAlpha = tNodeG.alpha * alpha;
  22346. if (tGraphicAlpha < 0.01)
  22347. return;
  22348. if (tNodeG.skin) {
  22349. tTex = this._getTextureByUrl(tNodeG.skin);
  22350. if (tTex) {
  22351. if (tResultTransform._checkTransform()) {
  22352. g.drawTexture(tTex, 0, 0, tNodeG.width, tNodeG.height, tResultTransform, tGraphicAlpha);
  22353. tNodeG.resultTransform = null;
  22354. }
  22355. else {
  22356. g.drawTexture(tTex, tResultTransform.tx, tResultTransform.ty, tNodeG.width, tNodeG.height, null, tGraphicAlpha);
  22357. }
  22358. }
  22359. }
  22360. var childs = node.child;
  22361. if (!childs)
  22362. return;
  22363. var i, len;
  22364. len = childs.length;
  22365. for (i = 0; i < len; i++) {
  22366. this._updateNodeGraphic(childs[i], frame, tResultTransform, g, tGraphicAlpha);
  22367. }
  22368. }
  22369. _updateNoChilds(tNodeG, g) {
  22370. if (!tNodeG.skin)
  22371. return;
  22372. var tTex = this._getTextureByUrl(tNodeG.skin);
  22373. if (!tTex)
  22374. return;
  22375. var tTransform = tNodeG.transform;
  22376. tTransform._checkTransform();
  22377. var onlyTranslate;
  22378. onlyTranslate = !tTransform._bTransform;
  22379. if (!onlyTranslate) {
  22380. g.drawTexture(tTex, 0, 0, tNodeG.width, tNodeG.height, tTransform.clone(), tNodeG.alpha);
  22381. }
  22382. else {
  22383. g.drawTexture(tTex, tTransform.tx, tTransform.ty, tNodeG.width, tNodeG.height, null, tNodeG.alpha);
  22384. }
  22385. }
  22386. _updateNodeGraphic2(node, frame, g) {
  22387. var tNodeG;
  22388. tNodeG = this._nodeGDic[node.compId] = this._getNodeGraphicData(node.compId, frame, this._nodeGDic[node.compId]);
  22389. if (!node.child) {
  22390. this._updateNoChilds(tNodeG, g);
  22391. return;
  22392. }
  22393. var tTransform = tNodeG.transform;
  22394. tTransform._checkTransform();
  22395. var onlyTranslate;
  22396. onlyTranslate = !tTransform._bTransform;
  22397. var hasTrans;
  22398. hasTrans = onlyTranslate && (tTransform.tx != 0 || tTransform.ty != 0);
  22399. var ifSave;
  22400. ifSave = (tTransform._bTransform) || tNodeG.alpha != 1;
  22401. if (ifSave)
  22402. g.save();
  22403. if (tNodeG.alpha != 1)
  22404. g.alpha(tNodeG.alpha);
  22405. if (!onlyTranslate)
  22406. g.transform(tTransform.clone());
  22407. else if (hasTrans)
  22408. g.translate(tTransform.tx, tTransform.ty);
  22409. var childs = node.child;
  22410. var tTex;
  22411. if (tNodeG.skin) {
  22412. tTex = this._getTextureByUrl(tNodeG.skin);
  22413. if (tTex) {
  22414. g.drawImage(tTex, 0, 0, tNodeG.width, tNodeG.height);
  22415. }
  22416. }
  22417. if (childs) {
  22418. var i, len;
  22419. len = childs.length;
  22420. for (i = 0; i < len; i++) {
  22421. this._updateNodeGraphic2(childs[i], frame, g);
  22422. }
  22423. }
  22424. if (ifSave) {
  22425. g.restore();
  22426. }
  22427. else {
  22428. if (!onlyTranslate) {
  22429. g.transform(tTransform.clone().invert());
  22430. }
  22431. else if (hasTrans) {
  22432. g.translate(-tTransform.tx, -tTransform.ty);
  22433. }
  22434. }
  22435. }
  22436. _calculateKeyFrames(node) {
  22437. super._calculateKeyFrames(node);
  22438. this._nodeIDAniDic[node.target] = node;
  22439. }
  22440. getNodeDataByID(nodeID) {
  22441. return this._nodeIDAniDic[nodeID];
  22442. }
  22443. _getParams(obj, params, frame, obj2) {
  22444. var rst = GraphicAnimation._temParam;
  22445. rst.length = params.length;
  22446. var i, len = params.length;
  22447. for (i = 0; i < len; i++) {
  22448. rst[i] = this._getObjVar(obj, params[i][0], frame, params[i][1], obj2);
  22449. }
  22450. return rst;
  22451. }
  22452. _getObjVar(obj, key, frame, noValue, obj2) {
  22453. if (key in obj) {
  22454. var vArr = obj[key];
  22455. if (frame >= vArr.length)
  22456. frame = vArr.length - 1;
  22457. return obj[key][frame];
  22458. }
  22459. if (key in obj2) {
  22460. return obj2[key];
  22461. }
  22462. return noValue;
  22463. }
  22464. _getNodeGraphicData(nodeID, frame, rst) {
  22465. if (!rst)
  22466. rst = new GraphicNode();
  22467. if (!rst.transform) {
  22468. rst.transform = new Matrix();
  22469. }
  22470. else {
  22471. rst.transform.identity();
  22472. }
  22473. var node = this.getNodeDataByID(nodeID);
  22474. if (!node)
  22475. return rst;
  22476. var frameData = node.frames;
  22477. var params = this._getParams(frameData, GraphicAnimation._drawTextureCmd, frame, this._nodeDefaultProps[nodeID]);
  22478. var url = params[0];
  22479. var width, height;
  22480. var px = params[5], py = params[6];
  22481. var aX = params[13], aY = params[14];
  22482. var sx = params[7], sy = params[8];
  22483. var rotate = params[9];
  22484. var skewX = params[11], skewY = params[12];
  22485. width = params[3];
  22486. height = params[4];
  22487. if (width == 0 || height == 0)
  22488. url = null;
  22489. if (width == -1)
  22490. width = 0;
  22491. if (height == -1)
  22492. height = 0;
  22493. var tex;
  22494. rst.skin = url;
  22495. rst.width = width;
  22496. rst.height = height;
  22497. if (url) {
  22498. tex = this._getTextureByUrl(url);
  22499. if (tex) {
  22500. if (!width)
  22501. width = tex.sourceWidth;
  22502. if (!height)
  22503. height = tex.sourceHeight;
  22504. }
  22505. else {
  22506. console.warn("lost skin:", url, ",you may load pics first");
  22507. }
  22508. }
  22509. rst.alpha = params[10];
  22510. var m = rst.transform;
  22511. if (aX != 0) {
  22512. px = aX * width;
  22513. }
  22514. if (aY != 0) {
  22515. py = aY * height;
  22516. }
  22517. if (px != 0 || py != 0) {
  22518. m.translate(-px, -py);
  22519. }
  22520. var tm = null;
  22521. if (rotate || sx !== 1 || sy !== 1 || skewX || skewY) {
  22522. tm = GraphicAnimation._tempMt;
  22523. tm.identity();
  22524. tm._bTransform = true;
  22525. var skx = (rotate - skewX) * 0.0174532922222222;
  22526. var sky = (rotate + skewY) * 0.0174532922222222;
  22527. var cx = Math.cos(sky);
  22528. var ssx = Math.sin(sky);
  22529. var cy = Math.sin(skx);
  22530. var ssy = Math.cos(skx);
  22531. tm.a = sx * cx;
  22532. tm.b = sx * ssx;
  22533. tm.c = -sy * cy;
  22534. tm.d = sy * ssy;
  22535. tm.tx = tm.ty = 0;
  22536. }
  22537. if (tm) {
  22538. m = Matrix.mul(m, tm, m);
  22539. }
  22540. m.translate(params[1], params[2]);
  22541. return rst;
  22542. }
  22543. _getTextureByUrl(url) {
  22544. return Loader.getRes(url);
  22545. }
  22546. setAniData(uiView, aniName = null) {
  22547. if (uiView.animations) {
  22548. this._nodeDefaultProps = {};
  22549. this._nodeGDic = {};
  22550. if (this._nodeList)
  22551. this._nodeList.length = 0;
  22552. this._rootNode = uiView;
  22553. this._parseNodeList(uiView);
  22554. var aniDic = {};
  22555. var anilist = [];
  22556. var animations = uiView.animations;
  22557. var i, len = animations.length;
  22558. var tAniO;
  22559. for (i = 0; i < len; i++) {
  22560. tAniO = animations[i];
  22561. this._labels = null;
  22562. if (aniName && aniName != tAniO.name) {
  22563. continue;
  22564. }
  22565. if (!tAniO)
  22566. continue;
  22567. try {
  22568. this._calGraphicData(tAniO);
  22569. }
  22570. catch (e) {
  22571. console.warn("parse animation fail:" + tAniO.name + ",empty animation created");
  22572. this._gList = [];
  22573. }
  22574. var frameO = {};
  22575. frameO.interval = 1000 / tAniO["frameRate"];
  22576. frameO.frames = this._gList;
  22577. frameO.labels = this._labels;
  22578. frameO.name = tAniO.name;
  22579. anilist.push(frameO);
  22580. aniDic[tAniO.name] = frameO;
  22581. }
  22582. this.animationList = anilist;
  22583. this.animationDic = aniDic;
  22584. }
  22585. GraphicAnimation._temParam.length = 0;
  22586. }
  22587. parseByData(aniData) {
  22588. var rootNode, aniO;
  22589. rootNode = aniData.nodeRoot;
  22590. aniO = aniData.aniO;
  22591. delete aniData.nodeRoot;
  22592. delete aniData.aniO;
  22593. this._nodeDefaultProps = {};
  22594. this._nodeGDic = {};
  22595. if (this._nodeList)
  22596. this._nodeList.length = 0;
  22597. this._rootNode = rootNode;
  22598. this._parseNodeList(rootNode);
  22599. this._labels = null;
  22600. try {
  22601. this._calGraphicData(aniO);
  22602. }
  22603. catch (e) {
  22604. console.warn("parse animation fail:" + aniO.name + ",empty animation created");
  22605. this._gList = [];
  22606. }
  22607. var frameO = aniData;
  22608. frameO.interval = 1000 / aniO["frameRate"];
  22609. frameO.frames = this._gList;
  22610. frameO.labels = this._labels;
  22611. frameO.name = aniO.name;
  22612. return frameO;
  22613. }
  22614. setUpAniData(uiView) {
  22615. if (uiView.animations) {
  22616. var aniDic = {};
  22617. var anilist = [];
  22618. var animations = uiView.animations;
  22619. var i, len = animations.length;
  22620. var tAniO;
  22621. for (i = 0; i < len; i++) {
  22622. tAniO = animations[i];
  22623. if (!tAniO)
  22624. continue;
  22625. var frameO = {};
  22626. frameO.name = tAniO.name;
  22627. frameO.aniO = tAniO;
  22628. frameO.nodeRoot = uiView;
  22629. anilist.push(frameO);
  22630. aniDic[tAniO.name] = frameO;
  22631. }
  22632. this.animationList = anilist;
  22633. this.animationDic = aniDic;
  22634. }
  22635. }
  22636. _clear() {
  22637. this.animationList = null;
  22638. this.animationDic = null;
  22639. this._gList = null;
  22640. this._nodeGDic = null;
  22641. }
  22642. static parseAnimationByData(animationObject) {
  22643. if (!GraphicAnimation._I)
  22644. GraphicAnimation._I = new GraphicAnimation();
  22645. var rst;
  22646. rst = GraphicAnimation._I.parseByData(animationObject);
  22647. GraphicAnimation._I._clear();
  22648. return rst;
  22649. }
  22650. static parseAnimationData(aniData) {
  22651. if (!GraphicAnimation._I)
  22652. GraphicAnimation._I = new GraphicAnimation();
  22653. GraphicAnimation._I.setUpAniData(aniData);
  22654. var rst;
  22655. rst = {};
  22656. rst.animationList = GraphicAnimation._I.animationList;
  22657. rst.animationDic = GraphicAnimation._I.animationDic;
  22658. GraphicAnimation._I._clear();
  22659. return rst;
  22660. }
  22661. }
  22662. 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]];
  22663. GraphicAnimation._temParam = [];
  22664. GraphicAnimation._tempMt = new Matrix();
  22665. class GraphicNode {
  22666. constructor() {
  22667. this.alpha = 1;
  22668. }
  22669. }
  22670. class Animation extends AnimationBase {
  22671. constructor() {
  22672. super();
  22673. this._setControlNode(this);
  22674. }
  22675. destroy(destroyChild = true) {
  22676. this.stop();
  22677. super.destroy(destroyChild);
  22678. this._frames = null;
  22679. this._labels = null;
  22680. }
  22681. play(start = 0, loop = true, name = "") {
  22682. if (name)
  22683. this._setFramesFromCache(name, true);
  22684. super.play(start, loop, name);
  22685. }
  22686. _setFramesFromCache(name, showWarn = false) {
  22687. if (this._url)
  22688. name = this._url + "#" + name;
  22689. if (name && Animation.framesMap[name]) {
  22690. var tAniO = Animation.framesMap[name];
  22691. if (tAniO instanceof Array) {
  22692. this._frames = Animation.framesMap[name];
  22693. this._count = this._frames.length;
  22694. }
  22695. else {
  22696. if (tAniO.nodeRoot) {
  22697. Animation.framesMap[name] = GraphicAnimation.parseAnimationByData(tAniO);
  22698. tAniO = Animation.framesMap[name];
  22699. }
  22700. this._frames = tAniO.frames;
  22701. this._count = this._frames.length;
  22702. if (!this._frameRateChanged)
  22703. this._interval = tAniO.interval;
  22704. this._labels = this._copyLabels(tAniO.labels);
  22705. }
  22706. return true;
  22707. }
  22708. else {
  22709. if (showWarn)
  22710. console.log("ani not found:", name);
  22711. }
  22712. return false;
  22713. }
  22714. _copyLabels(labels) {
  22715. if (!labels)
  22716. return null;
  22717. var rst;
  22718. rst = {};
  22719. var key;
  22720. for (key in labels) {
  22721. rst[key] = Utils.copyArray([], labels[key]);
  22722. }
  22723. return rst;
  22724. }
  22725. _frameLoop() {
  22726. if (this._visible && this._style.alpha > 0.01 && this._frames) {
  22727. super._frameLoop();
  22728. }
  22729. }
  22730. _displayToIndex(value) {
  22731. if (this._frames)
  22732. this.graphics = this._frames[value];
  22733. }
  22734. get frames() {
  22735. return this._frames;
  22736. }
  22737. set frames(value) {
  22738. this._frames = value;
  22739. if (value) {
  22740. this._count = value.length;
  22741. if (this._actionName)
  22742. this._setFramesFromCache(this._actionName, true);
  22743. this.index = this._index;
  22744. }
  22745. }
  22746. set source(value) {
  22747. if (value.indexOf(".ani") > -1)
  22748. this.loadAnimation(value);
  22749. else if (value.indexOf(".json") > -1 || value.indexOf("als") > -1 || value.indexOf("atlas") > -1)
  22750. this.loadAtlas(value);
  22751. else
  22752. this.loadImages(value.split(","));
  22753. }
  22754. set autoAnimation(value) {
  22755. this.play(0, true, value);
  22756. }
  22757. set autoPlay(value) {
  22758. if (value)
  22759. this.play();
  22760. else
  22761. this.stop();
  22762. }
  22763. clear() {
  22764. super.clear();
  22765. this.stop();
  22766. this.graphics = null;
  22767. this._frames = null;
  22768. this._labels = null;
  22769. return this;
  22770. }
  22771. loadImages(urls, cacheName = "") {
  22772. this._url = "";
  22773. if (!this._setFramesFromCache(cacheName)) {
  22774. this.frames = Animation.framesMap[cacheName] ? Animation.framesMap[cacheName] : Animation.createFrames(urls, cacheName);
  22775. }
  22776. return this;
  22777. }
  22778. loadAtlas(url, loaded = null, cacheName = "") {
  22779. this._url = "";
  22780. var _this = this;
  22781. if (!_this._setFramesFromCache(cacheName)) {
  22782. function onLoaded(loadUrl) {
  22783. if (url === loadUrl) {
  22784. _this.frames = Animation.framesMap[cacheName] ? Animation.framesMap[cacheName] : Animation.createFrames(url, cacheName);
  22785. if (loaded)
  22786. loaded.run();
  22787. }
  22788. }
  22789. if (Loader.getAtlas(url))
  22790. onLoaded(url);
  22791. else
  22792. ILaya.loader.load(url, Handler.create(null, onLoaded, [url]), null, Loader.ATLAS);
  22793. }
  22794. return this;
  22795. }
  22796. loadAnimation(url, loaded = null, atlas = null) {
  22797. this._url = url;
  22798. var _this = this;
  22799. if (!this._actionName)
  22800. this._actionName = "";
  22801. if (!_this._setFramesFromCache(this._actionName)) {
  22802. if (!atlas || Loader.getAtlas(atlas)) {
  22803. this._loadAnimationData(url, loaded, atlas);
  22804. }
  22805. else {
  22806. ILaya.loader.load(atlas, Handler.create(this, this._loadAnimationData, [url, loaded, atlas]), null, Loader.ATLAS);
  22807. }
  22808. }
  22809. else {
  22810. _this._setFramesFromCache(this._actionName, true);
  22811. this.index = 0;
  22812. if (loaded)
  22813. loaded.run();
  22814. }
  22815. return this;
  22816. }
  22817. _loadAnimationData(url, loaded = null, atlas = null) {
  22818. if (atlas && !Loader.getAtlas(atlas)) {
  22819. console.warn("atlas load fail:" + atlas);
  22820. return;
  22821. }
  22822. var _this = this;
  22823. function onLoaded(loadUrl) {
  22824. if (!Loader.getRes(loadUrl)) {
  22825. if (Animation.framesMap[url + "#"]) {
  22826. _this._setFramesFromCache(this._actionName, true);
  22827. _this.index = 0;
  22828. _this._resumePlay();
  22829. if (loaded)
  22830. loaded.run();
  22831. }
  22832. return;
  22833. }
  22834. if (url === loadUrl) {
  22835. var tAniO;
  22836. if (!Animation.framesMap[url + "#"]) {
  22837. var aniData = GraphicAnimation.parseAnimationData(Loader.getRes(url));
  22838. if (!aniData)
  22839. return;
  22840. var aniList = aniData.animationList;
  22841. var i, len = aniList.length;
  22842. var defaultO;
  22843. for (i = 0; i < len; i++) {
  22844. tAniO = aniList[i];
  22845. Animation.framesMap[url + "#" + tAniO.name] = tAniO;
  22846. if (!defaultO)
  22847. defaultO = tAniO;
  22848. }
  22849. if (defaultO) {
  22850. Animation.framesMap[url + "#"] = defaultO;
  22851. _this._setFramesFromCache(_this._actionName, true);
  22852. _this.index = 0;
  22853. }
  22854. _this._resumePlay();
  22855. }
  22856. else {
  22857. _this._setFramesFromCache(_this._actionName, true);
  22858. _this.index = 0;
  22859. _this._resumePlay();
  22860. }
  22861. if (loaded)
  22862. loaded.run();
  22863. }
  22864. Loader.clearRes(url);
  22865. }
  22866. if (Loader.getRes(url))
  22867. onLoaded(url);
  22868. else
  22869. ILaya.loader.load(url, Handler.create(null, onLoaded, [url]), null, Loader.JSON);
  22870. }
  22871. static createFrames(url, name) {
  22872. var arr;
  22873. if (typeof (url) == 'string') {
  22874. var atlas = Loader.getAtlas(url);
  22875. if (atlas && atlas.length) {
  22876. arr = [];
  22877. for (var i = 0, n = atlas.length; i < n; i++) {
  22878. var g = new Graphics();
  22879. g.drawImage(Loader.getRes(atlas[i]), 0, 0);
  22880. arr.push(g);
  22881. }
  22882. }
  22883. }
  22884. else if (url instanceof Array) {
  22885. arr = [];
  22886. for (i = 0, n = url.length; i < n; i++) {
  22887. g = new Graphics();
  22888. g.loadImage(url[i], 0, 0);
  22889. arr.push(g);
  22890. }
  22891. }
  22892. if (name)
  22893. Animation.framesMap[name] = arr;
  22894. return arr;
  22895. }
  22896. static clearCache(key) {
  22897. var cache = Animation.framesMap;
  22898. var val;
  22899. var key2 = key + "#";
  22900. for (val in cache) {
  22901. if (val === key || val.indexOf(key2) === 0) {
  22902. delete Animation.framesMap[val];
  22903. }
  22904. }
  22905. }
  22906. }
  22907. Animation.framesMap = {};
  22908. ILaya.regClass(Animation);
  22909. ClassUtils.regClass("laya.display.Animation", Animation);
  22910. ClassUtils.regClass("Laya.Animation", Animation);
  22911. class EffectAnimation extends FrameAnimation {
  22912. constructor() {
  22913. super(...arguments);
  22914. this._initData = {};
  22915. }
  22916. set target(v) {
  22917. if (this._target)
  22918. this._target.off(EffectAnimation.EFFECT_BEGIN, this, this._onOtherBegin);
  22919. this._target = v;
  22920. if (this._target)
  22921. this._target.on(EffectAnimation.EFFECT_BEGIN, this, this._onOtherBegin);
  22922. this._addEvent();
  22923. }
  22924. get target() {
  22925. return this._target;
  22926. }
  22927. _onOtherBegin(effect) {
  22928. if (effect === this)
  22929. return;
  22930. this.stop();
  22931. }
  22932. set playEvent(event) {
  22933. this._playEvent = event;
  22934. if (!event)
  22935. return;
  22936. this._addEvent();
  22937. }
  22938. _addEvent() {
  22939. if (!this._target || !this._playEvent)
  22940. return;
  22941. this._setControlNode(this._target);
  22942. this._target.on(this._playEvent, this, this._onPlayAction);
  22943. }
  22944. _onPlayAction() {
  22945. this.play(0, false);
  22946. }
  22947. play(start = 0, loop = true, name = "") {
  22948. if (!this._target)
  22949. return;
  22950. this._target.event(EffectAnimation.EFFECT_BEGIN, [this]);
  22951. this._recordInitData();
  22952. super.play(start, loop, name);
  22953. }
  22954. _recordInitData() {
  22955. if (!this._aniKeys)
  22956. return;
  22957. var i, len;
  22958. len = this._aniKeys.length;
  22959. var key;
  22960. for (i = 0; i < len; i++) {
  22961. key = this._aniKeys[i];
  22962. this._initData[key] = this._target[key];
  22963. }
  22964. }
  22965. set effectClass(classStr) {
  22966. this._effectClass = ClassUtils.getClass(classStr);
  22967. if (this._effectClass) {
  22968. var uiData = this._effectClass["uiView"];
  22969. if (uiData) {
  22970. var aniData = uiData["animations"];
  22971. if (aniData && aniData[0]) {
  22972. var data = aniData[0];
  22973. this._setUp({}, data);
  22974. if (data.nodes && data.nodes[0]) {
  22975. this._aniKeys = data.nodes[0].keys;
  22976. }
  22977. }
  22978. }
  22979. }
  22980. }
  22981. set effectData(uiData) {
  22982. if (uiData) {
  22983. var aniData = uiData["animations"];
  22984. if (aniData && aniData[0]) {
  22985. var data = aniData[0];
  22986. this._setUp({}, data);
  22987. if (data.nodes && data.nodes[0]) {
  22988. this._aniKeys = data.nodes[0].keys;
  22989. }
  22990. }
  22991. }
  22992. }
  22993. _displayToIndex(value) {
  22994. if (!this._animationData)
  22995. return;
  22996. if (value < 0)
  22997. value = 0;
  22998. if (value > this._count)
  22999. value = this._count;
  23000. var nodes = this._animationData.nodes, i, len = nodes.length;
  23001. len = len > 1 ? 1 : len;
  23002. for (i = 0; i < len; i++) {
  23003. this._displayNodeToFrame(nodes[i], value);
  23004. }
  23005. }
  23006. _displayNodeToFrame(node, frame, targetDic = null) {
  23007. if (!this._target)
  23008. return;
  23009. var target = this._target;
  23010. var frames = node.frames, key, propFrames, value;
  23011. var keys = node.keys, i, len = keys.length;
  23012. var secondFrames = node.secondFrames;
  23013. var tSecondFrame;
  23014. var easeFun;
  23015. var tKeyFrames;
  23016. var startFrame;
  23017. var endFrame;
  23018. for (i = 0; i < len; i++) {
  23019. key = keys[i];
  23020. propFrames = frames[key];
  23021. tSecondFrame = secondFrames[key];
  23022. if (tSecondFrame == -1) {
  23023. value = this._initData[key];
  23024. }
  23025. else {
  23026. if (frame < tSecondFrame) {
  23027. tKeyFrames = node.keyframes[key];
  23028. startFrame = tKeyFrames[0];
  23029. if (startFrame.tween) {
  23030. easeFun = Ease[startFrame.tweenMethod];
  23031. if (easeFun == null)
  23032. easeFun = Ease.linearNone;
  23033. endFrame = tKeyFrames[1];
  23034. value = easeFun(frame, this._initData[key], endFrame.value - this._initData[key], endFrame.index);
  23035. }
  23036. else {
  23037. value = this._initData[key];
  23038. }
  23039. }
  23040. else {
  23041. if (propFrames.length > frame)
  23042. value = propFrames[frame];
  23043. else
  23044. value = propFrames[propFrames.length - 1];
  23045. }
  23046. }
  23047. target[key] = value;
  23048. }
  23049. }
  23050. _calculateKeyFrames(node) {
  23051. super._calculateKeyFrames(node);
  23052. var keyFrames = node.keyframes, key, tKeyFrames, target = node.target;
  23053. var secondFrames = {};
  23054. node.secondFrames = secondFrames;
  23055. for (key in keyFrames) {
  23056. tKeyFrames = keyFrames[key];
  23057. if (tKeyFrames.length <= 1)
  23058. secondFrames[key] = -1;
  23059. else
  23060. secondFrames[key] = tKeyFrames[1].index;
  23061. }
  23062. }
  23063. }
  23064. EffectAnimation.EFFECT_BEGIN = "effectbegin";
  23065. ClassUtils.regClass("laya.display.EffectAnimation", EffectAnimation);
  23066. ClassUtils.regClass("Laya.EffectAnimation", EffectAnimation);
  23067. class SceneLoader extends EventDispatcher {
  23068. constructor() {
  23069. super();
  23070. this._completeHandler = new Handler(this, this.onOneLoadComplete);
  23071. this.reset();
  23072. }
  23073. reset() {
  23074. this._toLoadList = [];
  23075. this._isLoading = false;
  23076. this.totalCount = 0;
  23077. }
  23078. get leftCount() {
  23079. if (this._isLoading)
  23080. return this._toLoadList.length + 1;
  23081. return this._toLoadList.length;
  23082. }
  23083. get loadedCount() {
  23084. return this.totalCount - this.leftCount;
  23085. }
  23086. load(url, is3D = false, ifCheck = true) {
  23087. if (url instanceof Array) {
  23088. var i, len;
  23089. len = url.length;
  23090. for (i = 0; i < len; i++) {
  23091. this._addToLoadList(url[i], is3D);
  23092. }
  23093. }
  23094. else {
  23095. this._addToLoadList(url, is3D);
  23096. }
  23097. if (ifCheck)
  23098. this._checkNext();
  23099. }
  23100. _addToLoadList(url, is3D = false) {
  23101. if (this._toLoadList.indexOf(url) >= 0)
  23102. return;
  23103. if (Loader.getRes(url))
  23104. return;
  23105. if (is3D) {
  23106. this._toLoadList.push({ url: url });
  23107. }
  23108. else
  23109. this._toLoadList.push(url);
  23110. this.totalCount++;
  23111. }
  23112. _checkNext() {
  23113. if (!this._isLoading) {
  23114. if (this._toLoadList.length == 0) {
  23115. this.event(Event.COMPLETE);
  23116. return;
  23117. }
  23118. var tItem;
  23119. tItem = this._toLoadList.pop();
  23120. if (typeof (tItem) == 'string') {
  23121. this.loadOne(tItem);
  23122. }
  23123. else {
  23124. this.loadOne(tItem.url, true);
  23125. }
  23126. }
  23127. }
  23128. loadOne(url, is3D = false) {
  23129. this._curUrl = url;
  23130. var type = Utils.getFileExtension(this._curUrl);
  23131. if (is3D) {
  23132. ILaya.loader.create(url, this._completeHandler);
  23133. }
  23134. else if (SceneLoader.LoadableExtensions[type]) {
  23135. ILaya.loader.load(url, this._completeHandler, null, SceneLoader.LoadableExtensions[type]);
  23136. }
  23137. else if (url != AtlasInfoManager.getFileLoadPath(url) || SceneLoader.No3dLoadTypes[type] || !LoaderManager.createMap[type]) {
  23138. ILaya.loader.load(url, this._completeHandler);
  23139. }
  23140. else {
  23141. ILaya.loader.create(url, this._completeHandler);
  23142. }
  23143. }
  23144. onOneLoadComplete() {
  23145. this._isLoading = false;
  23146. if (!Loader.getRes(this._curUrl)) {
  23147. console.log("Fail to load:", this._curUrl);
  23148. }
  23149. var type = Utils.getFileExtension(this._curUrl);
  23150. if (SceneLoader.LoadableExtensions[type]) {
  23151. var dataO;
  23152. dataO = Loader.getRes(this._curUrl);
  23153. if (dataO && (dataO instanceof Prefab)) {
  23154. dataO = dataO.json;
  23155. }
  23156. if (dataO) {
  23157. if (dataO.loadList) {
  23158. this.load(dataO.loadList, false, false);
  23159. }
  23160. if (dataO.loadList3D) {
  23161. this.load(dataO.loadList3D, true, false);
  23162. }
  23163. }
  23164. }
  23165. if (type == "sk") {
  23166. this.load(this._curUrl.replace(".sk", ".png"), false, false);
  23167. }
  23168. this.event(Event.PROGRESS, this.getProgress());
  23169. this._checkNext();
  23170. }
  23171. getProgress() {
  23172. return this.loadedCount / this.totalCount;
  23173. }
  23174. }
  23175. SceneLoader.LoadableExtensions = { "scene": Loader.JSON, "scene3d": Loader.JSON, "ani": Loader.JSON, "ui": Loader.JSON, "prefab": Loader.PREFAB };
  23176. SceneLoader.No3dLoadTypes = { "png": true, "jpg": true, "txt": true };
  23177. class Scene extends Sprite {
  23178. constructor(createChildren = true) {
  23179. super();
  23180. this.autoDestroyAtClosed = false;
  23181. this.url = null;
  23182. this._viewCreated = false;
  23183. this._$componentType = "Scene";
  23184. this._setBit(Const.NOT_READY, true);
  23185. Scene.unDestroyedScenes.push(this);
  23186. this._scene = this;
  23187. if (createChildren)
  23188. this.createChildren();
  23189. }
  23190. createChildren() {
  23191. }
  23192. loadScene(path) {
  23193. var url = path.indexOf(".") > -1 ? path : path + ".scene";
  23194. var view = ILaya.loader.getRes(url);
  23195. if (view) {
  23196. this.createView(view);
  23197. }
  23198. else {
  23199. ILaya.loader.resetProgress();
  23200. var loader = new SceneLoader();
  23201. loader.on(Event.COMPLETE, this, this._onSceneLoaded, [url]);
  23202. loader.load(url);
  23203. }
  23204. }
  23205. _onSceneLoaded(url) {
  23206. this.createView(ILaya.Loader.getRes(url));
  23207. }
  23208. createView(view) {
  23209. if (view && !this._viewCreated) {
  23210. this._viewCreated = true;
  23211. SceneUtils.createByData(this, view);
  23212. }
  23213. }
  23214. getNodeByID(id) {
  23215. if (this._idMap)
  23216. return this._idMap[id];
  23217. return null;
  23218. }
  23219. open(closeOther = true, param = null) {
  23220. if (closeOther)
  23221. Scene.closeAll();
  23222. Scene.root.addChild(this);
  23223. this.onOpened(param);
  23224. }
  23225. onOpened(param) {
  23226. }
  23227. close(type = null) {
  23228. this.onClosed(type);
  23229. if (this.autoDestroyAtClosed)
  23230. this.destroy();
  23231. else
  23232. this.removeSelf();
  23233. }
  23234. onClosed(type = null) {
  23235. }
  23236. destroy(destroyChild = true) {
  23237. this._idMap = null;
  23238. super.destroy(destroyChild);
  23239. var list = Scene.unDestroyedScenes;
  23240. for (var i = list.length - 1; i > -1; i--) {
  23241. if (list[i] === this) {
  23242. list.splice(i, 1);
  23243. return;
  23244. }
  23245. }
  23246. }
  23247. set scaleX(value) {
  23248. if (super.get_scaleX() == value)
  23249. return;
  23250. super.set_scaleX(value);
  23251. this.event(Event.RESIZE);
  23252. }
  23253. get scaleX() {
  23254. return super.scaleX;
  23255. }
  23256. set scaleY(value) {
  23257. if (super.get_scaleY() == value)
  23258. return;
  23259. super.set_scaleY(value);
  23260. this.event(Event.RESIZE);
  23261. }
  23262. get scaleY() {
  23263. return super.scaleY;
  23264. }
  23265. get width() {
  23266. if (this._width)
  23267. return this._width;
  23268. var max = 0;
  23269. for (var i = this.numChildren - 1; i > -1; i--) {
  23270. var comp = this.getChildAt(i);
  23271. if (comp._visible) {
  23272. max = Math.max(comp._x + comp.width * comp.scaleX, max);
  23273. }
  23274. }
  23275. return max;
  23276. }
  23277. set width(value) {
  23278. if (super.get_width() == value)
  23279. return;
  23280. super.set_width(value);
  23281. this.callLater(this._sizeChanged);
  23282. }
  23283. get height() {
  23284. if (this._height)
  23285. return this._height;
  23286. var max = 0;
  23287. for (var i = this.numChildren - 1; i > -1; i--) {
  23288. var comp = this.getChildAt(i);
  23289. if (comp._visible) {
  23290. max = Math.max(comp._y + comp.height * comp.scaleY, max);
  23291. }
  23292. }
  23293. return max;
  23294. }
  23295. set height(value) {
  23296. if (super.get_height() == value)
  23297. return;
  23298. super.set_height(value);
  23299. this.callLater(this._sizeChanged);
  23300. }
  23301. _sizeChanged() {
  23302. this.event(Event.RESIZE);
  23303. }
  23304. static get root() {
  23305. if (!Scene._root) {
  23306. Scene._root = ILaya.stage.addChild(new Sprite());
  23307. Scene._root.name = "root";
  23308. ILaya.stage.on("resize", null, () => {
  23309. Scene._root.size(ILaya.stage.width, ILaya.stage.height);
  23310. Scene._root.event(Event.RESIZE);
  23311. });
  23312. Scene._root.size(ILaya.stage.width, ILaya.stage.height);
  23313. Scene._root.event(Event.RESIZE);
  23314. }
  23315. return Scene._root;
  23316. }
  23317. get timer() {
  23318. return this._timer || ILaya.timer;
  23319. }
  23320. set timer(value) {
  23321. this._timer = value;
  23322. }
  23323. static load(url, complete = null, progress = null) {
  23324. ILaya.loader.resetProgress();
  23325. var loader = new SceneLoader();
  23326. loader.on(Event.PROGRESS, null, onProgress);
  23327. loader.once(Event.COMPLETE, null, create);
  23328. loader.load(url);
  23329. function onProgress(value) {
  23330. if (Scene._loadPage)
  23331. Scene._loadPage.event("progress", value);
  23332. progress && progress.runWith(value);
  23333. }
  23334. function create() {
  23335. loader.off(Event.PROGRESS, null, onProgress);
  23336. var obj = ILaya.Loader.getRes(url);
  23337. if (!obj)
  23338. throw "Can not find scene:" + url;
  23339. if (!obj.props)
  23340. throw "Scene data is error:" + url;
  23341. var runtime = obj.props.runtime ? obj.props.runtime : obj.type;
  23342. var clas = ILaya.ClassUtils.getClass(runtime);
  23343. if (obj.props.renderType == "instance") {
  23344. var scene = clas.instance || (clas.instance = new clas());
  23345. }
  23346. else {
  23347. scene = new clas();
  23348. }
  23349. if (scene && scene instanceof Node) {
  23350. scene.url = url;
  23351. if (!scene._getBit(Const.NOT_READY)) {
  23352. complete && complete.runWith(scene);
  23353. }
  23354. else {
  23355. scene.on("onViewCreated", null, function () {
  23356. complete && complete.runWith(scene);
  23357. });
  23358. scene.createView(obj);
  23359. }
  23360. Scene.hideLoadingPage();
  23361. }
  23362. else {
  23363. throw "Can not find scene:" + runtime;
  23364. }
  23365. }
  23366. }
  23367. static open(url, closeOther = true, param = null, complete = null, progress = null) {
  23368. if (param instanceof Handler) {
  23369. var temp = complete;
  23370. complete = param;
  23371. param = temp;
  23372. }
  23373. Scene.showLoadingPage();
  23374. Scene.load(url, Handler.create(null, this._onSceneLoaded, [closeOther, complete, param]), progress);
  23375. }
  23376. static _onSceneLoaded(closeOther, complete, param, scene) {
  23377. scene.open(closeOther, param);
  23378. if (complete)
  23379. complete.runWith(scene);
  23380. }
  23381. static close(url, name = "") {
  23382. var flag = false;
  23383. var list = Scene.unDestroyedScenes;
  23384. for (var i = 0, n = list.length; i < n; i++) {
  23385. var scene = list[i];
  23386. if (scene && scene.parent && scene.url === url && scene.name == name) {
  23387. scene.close();
  23388. flag = true;
  23389. }
  23390. }
  23391. return flag;
  23392. }
  23393. static closeAll() {
  23394. var root = Scene.root;
  23395. for (var i = 0, n = root.numChildren; i < n; i++) {
  23396. var scene = root.getChildAt(0);
  23397. if (scene instanceof Scene)
  23398. scene.close();
  23399. else
  23400. scene.removeSelf();
  23401. }
  23402. }
  23403. static destroy(url, name = "") {
  23404. var flag = false;
  23405. var list = Scene.unDestroyedScenes;
  23406. for (var i = 0, n = list.length; i < n; i++) {
  23407. var scene = list[i];
  23408. if (scene.url === url && scene.name == name) {
  23409. scene.destroy();
  23410. flag = true;
  23411. }
  23412. }
  23413. return flag;
  23414. }
  23415. static gc() {
  23416. Resource.destroyUnusedResources();
  23417. }
  23418. static setLoadingPage(loadPage) {
  23419. if (Scene._loadPage != loadPage) {
  23420. Scene._loadPage = loadPage;
  23421. }
  23422. }
  23423. static showLoadingPage(param = null, delay = 500) {
  23424. if (Scene._loadPage) {
  23425. ILaya.systemTimer.clear(null, Scene._showLoading);
  23426. ILaya.systemTimer.clear(null, Scene._hideLoading);
  23427. ILaya.systemTimer.once(delay, null, Scene._showLoading, [param], false);
  23428. }
  23429. }
  23430. static _showLoading(param) {
  23431. ILaya.stage.addChild(Scene._loadPage);
  23432. Scene._loadPage.onOpened(param);
  23433. }
  23434. static _hideLoading() {
  23435. Scene._loadPage.close();
  23436. }
  23437. static hideLoadingPage(delay = 500) {
  23438. if (Scene._loadPage) {
  23439. ILaya.systemTimer.clear(null, Scene._showLoading);
  23440. ILaya.systemTimer.clear(null, Scene._hideLoading);
  23441. ILaya.systemTimer.once(delay, null, Scene._hideLoading);
  23442. }
  23443. }
  23444. }
  23445. Scene.unDestroyedScenes = [];
  23446. ILaya.regClass(Scene);
  23447. ClassUtils.regClass("laya.display.Scene", Scene);
  23448. ClassUtils.regClass("Laya.Scene", Scene);
  23449. class DrawCanvasCmd {
  23450. constructor() {
  23451. this._paramData = null;
  23452. }
  23453. static create(texture, x, y, width, height) {
  23454. return null;
  23455. }
  23456. recover() {
  23457. this._graphicsCmdEncoder = null;
  23458. Pool.recover("DrawCanvasCmd", this);
  23459. }
  23460. get cmdID() {
  23461. return DrawCanvasCmd.ID;
  23462. }
  23463. }
  23464. DrawCanvasCmd.ID = "DrawCanvasCmd";
  23465. DrawCanvasCmd._DRAW_IMAGE_CMD_ENCODER_ = null;
  23466. DrawCanvasCmd._PARAM_TEXTURE_POS_ = 2;
  23467. DrawCanvasCmd._PARAM_VB_POS_ = 5;
  23468. class DrawParticleCmd {
  23469. static create(_temp) {
  23470. var cmd = Pool.getItemByClass("DrawParticleCmd", DrawParticleCmd);
  23471. cmd._templ = _temp;
  23472. return cmd;
  23473. }
  23474. recover() {
  23475. this._templ = null;
  23476. Pool.recover("DrawParticleCmd", this);
  23477. }
  23478. run(context, gx, gy) {
  23479. context.drawParticle(gx, gy, this._templ);
  23480. }
  23481. get cmdID() {
  23482. return DrawParticleCmd.ID;
  23483. }
  23484. }
  23485. DrawParticleCmd.ID = "DrawParticleCmd";
  23486. class FilterSetterBase {
  23487. constructor() {
  23488. }
  23489. paramChanged() {
  23490. Laya.systemTimer.callLater(this, this.buildFilter);
  23491. }
  23492. buildFilter() {
  23493. if (this._target) {
  23494. this.addFilter(this._target);
  23495. }
  23496. }
  23497. addFilter(sprite) {
  23498. if (!sprite)
  23499. return;
  23500. if (!sprite.filters) {
  23501. sprite.filters = [this._filter];
  23502. }
  23503. else {
  23504. var preFilters;
  23505. preFilters = sprite.filters;
  23506. if (preFilters.indexOf(this._filter) < 0) {
  23507. preFilters.push(this._filter);
  23508. sprite.filters = Utils.copyArray([], preFilters);
  23509. }
  23510. }
  23511. }
  23512. removeFilter(sprite) {
  23513. if (!sprite)
  23514. return;
  23515. sprite.filters = null;
  23516. }
  23517. set target(value) {
  23518. if (this._target != value) {
  23519. this._target = value;
  23520. this.paramChanged();
  23521. }
  23522. }
  23523. }
  23524. class BlurFilterGLRender {
  23525. render(rt, ctx, width, height, filter) {
  23526. var shaderValue = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  23527. this.setShaderInfo(shaderValue, filter, rt.width, rt.height);
  23528. ctx.drawTarget(rt, 0, 0, width, height, Matrix.EMPTY.identity(), shaderValue);
  23529. }
  23530. setShaderInfo(shader, filter, w, h) {
  23531. shader.defines.add(Filter.BLUR);
  23532. var sv = shader;
  23533. BlurFilterGLRender.blurinfo[0] = w;
  23534. BlurFilterGLRender.blurinfo[1] = h;
  23535. sv.blurInfo = BlurFilterGLRender.blurinfo;
  23536. var sigma = filter.strength / 3.0;
  23537. var sigma2 = sigma * sigma;
  23538. filter.strength_sig2_2sig2_gauss1[0] = filter.strength;
  23539. filter.strength_sig2_2sig2_gauss1[1] = sigma2;
  23540. filter.strength_sig2_2sig2_gauss1[2] = 2.0 * sigma2;
  23541. filter.strength_sig2_2sig2_gauss1[3] = 1.0 / (2.0 * Math.PI * sigma2);
  23542. sv.strength_sig2_2sig2_gauss1 = filter.strength_sig2_2sig2_gauss1;
  23543. }
  23544. }
  23545. BlurFilterGLRender.blurinfo = new Array(2);
  23546. class BlurFilter extends Filter {
  23547. constructor(strength = 4) {
  23548. super();
  23549. this.strength_sig2_2sig2_gauss1 = [];
  23550. this.strength = strength;
  23551. this._glRender = new BlurFilterGLRender();
  23552. }
  23553. get type() {
  23554. return Filter.BLUR;
  23555. }
  23556. getStrenth_sig2_2sig2_native() {
  23557. if (!this.strength_sig2_native) {
  23558. this.strength_sig2_native = new Float32Array(4);
  23559. }
  23560. var sigma = this.strength / 3.0;
  23561. var sigma2 = sigma * sigma;
  23562. this.strength_sig2_native[0] = this.strength;
  23563. this.strength_sig2_native[1] = sigma2;
  23564. this.strength_sig2_native[2] = 2.0 * sigma2;
  23565. this.strength_sig2_native[3] = 1.0 / (2.0 * Math.PI * sigma2);
  23566. return this.strength_sig2_native;
  23567. }
  23568. }
  23569. class BlurFilterSetter extends FilterSetterBase {
  23570. constructor() {
  23571. super();
  23572. this._strength = 4;
  23573. this._filter = new BlurFilter(this.strength);
  23574. }
  23575. buildFilter() {
  23576. this._filter = new BlurFilter(this.strength);
  23577. super.buildFilter();
  23578. }
  23579. get strength() {
  23580. return this._strength;
  23581. }
  23582. set strength(value) {
  23583. this._strength = value;
  23584. }
  23585. }
  23586. class ButtonEffect {
  23587. constructor() {
  23588. this._curState = 0;
  23589. this.effectScale = 1.5;
  23590. this.tweenTime = 300;
  23591. }
  23592. set target(tar) {
  23593. this._tar = tar;
  23594. tar.on(Event.MOUSE_DOWN, this, this.toChangedState);
  23595. tar.on(Event.MOUSE_UP, this, this.toInitState);
  23596. tar.on(Event.MOUSE_OUT, this, this.toInitState);
  23597. }
  23598. toChangedState() {
  23599. this._curState = 1;
  23600. if (this._curTween)
  23601. Tween.clear(this._curTween);
  23602. this._curTween = Tween.to(this._tar, { scaleX: this.effectScale, scaleY: this.effectScale }, this.tweenTime, Ease[this.effectEase], Handler.create(this, this.tweenComplete));
  23603. }
  23604. toInitState() {
  23605. if (this._curState == 2)
  23606. return;
  23607. if (this._curTween)
  23608. Tween.clear(this._curTween);
  23609. this._curState = 2;
  23610. this._curTween = Tween.to(this._tar, { scaleX: 1, scaleY: 1 }, this.tweenTime, Ease[this.backEase], Handler.create(this, this.tweenComplete));
  23611. }
  23612. tweenComplete() {
  23613. this._curState = 0;
  23614. this._curTween = null;
  23615. }
  23616. }
  23617. class ColorFilterSetter extends FilterSetterBase {
  23618. constructor() {
  23619. super();
  23620. this._brightness = 0;
  23621. this._contrast = 0;
  23622. this._saturation = 0;
  23623. this._hue = 0;
  23624. this._red = 0;
  23625. this._green = 0;
  23626. this._blue = 0;
  23627. this._alpha = 0;
  23628. this._filter = new ColorFilter();
  23629. }
  23630. buildFilter() {
  23631. this._filter.reset();
  23632. this._filter.color(this.red, this.green, this.blue, this.alpha);
  23633. this._filter.adjustHue(this.hue);
  23634. this._filter.adjustContrast(this.contrast);
  23635. this._filter.adjustBrightness(this.brightness);
  23636. this._filter.adjustSaturation(this.saturation);
  23637. super.buildFilter();
  23638. }
  23639. get brightness() {
  23640. return this._brightness;
  23641. }
  23642. set brightness(value) {
  23643. this._brightness = value;
  23644. this.paramChanged();
  23645. }
  23646. get contrast() {
  23647. return this._contrast;
  23648. }
  23649. set contrast(value) {
  23650. this._contrast = value;
  23651. this.paramChanged();
  23652. }
  23653. get saturation() {
  23654. return this._saturation;
  23655. }
  23656. set saturation(value) {
  23657. this._saturation = value;
  23658. this.paramChanged();
  23659. }
  23660. get hue() {
  23661. return this._hue;
  23662. }
  23663. set hue(value) {
  23664. this._hue = value;
  23665. this.paramChanged();
  23666. }
  23667. get red() {
  23668. return this._red;
  23669. }
  23670. set red(value) {
  23671. this._red = value;
  23672. this.paramChanged();
  23673. }
  23674. get green() {
  23675. return this._green;
  23676. }
  23677. set green(value) {
  23678. this._green = value;
  23679. this.paramChanged();
  23680. }
  23681. get blue() {
  23682. return this._blue;
  23683. }
  23684. set blue(value) {
  23685. this._blue = value;
  23686. this.paramChanged();
  23687. }
  23688. get color() {
  23689. return this._color;
  23690. }
  23691. set color(value) {
  23692. this._color = value;
  23693. var colorO;
  23694. colorO = ColorUtils.create(value);
  23695. this._red = colorO.arrColor[0] * 255;
  23696. this._green = colorO.arrColor[1] * 255;
  23697. this._blue = colorO.arrColor[2] * 255;
  23698. this.paramChanged();
  23699. }
  23700. get alpha() {
  23701. return this._alpha;
  23702. }
  23703. set alpha(value) {
  23704. this._alpha = value;
  23705. this.paramChanged();
  23706. }
  23707. }
  23708. class EffectBase extends Component {
  23709. constructor() {
  23710. super(...arguments);
  23711. this.duration = 1000;
  23712. this.delay = 0;
  23713. this.repeat = 0;
  23714. this.autoDestroyAtComplete = true;
  23715. }
  23716. _onAwake() {
  23717. this.target = this.target || this.owner;
  23718. if (this.autoDestroyAtComplete)
  23719. this._comlete = Handler.create(this.target, this.target.destroy, null, false);
  23720. if (this.eventName)
  23721. this.owner.on(this.eventName, this, this._exeTween);
  23722. else
  23723. this._exeTween();
  23724. }
  23725. _exeTween() {
  23726. this._tween = this._doTween();
  23727. this._tween.repeat = this.repeat;
  23728. }
  23729. _doTween() {
  23730. return null;
  23731. }
  23732. onReset() {
  23733. this.duration = 1000;
  23734. this.delay = 0;
  23735. this.repeat = 0;
  23736. this.ease = null;
  23737. this.target = null;
  23738. if (this.eventName) {
  23739. this.owner.off(this.eventName, this, this._exeTween);
  23740. this.eventName = null;
  23741. }
  23742. if (this._comlete) {
  23743. this._comlete.recover();
  23744. this._comlete = null;
  23745. }
  23746. if (this._tween) {
  23747. this._tween.clear();
  23748. this._tween = null;
  23749. }
  23750. }
  23751. }
  23752. class FadeIn extends EffectBase {
  23753. _doTween() {
  23754. this.target.alpha = 0;
  23755. return Tween.to(this.target, { alpha: 1 }, this.duration, Ease[this.ease], this._comlete, this.delay);
  23756. }
  23757. }
  23758. class FadeOut extends EffectBase {
  23759. _doTween() {
  23760. this.target.alpha = 1;
  23761. return Tween.to(this.target, { alpha: 0 }, this.duration, Ease[this.ease], this._comlete, this.delay);
  23762. }
  23763. }
  23764. class GlowFilterGLRender {
  23765. setShaderInfo(shader, w, h, data) {
  23766. shader.defines.add(data.type);
  23767. var sv = shader;
  23768. sv.u_blurInfo1 = data._sv_blurInfo1;
  23769. var info2 = data._sv_blurInfo2;
  23770. info2[0] = w;
  23771. info2[1] = h;
  23772. sv.u_blurInfo2 = info2;
  23773. sv.u_color = data.getColor();
  23774. }
  23775. render(rt, ctx, width, height, filter) {
  23776. var w = width, h = height;
  23777. var svBlur = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  23778. this.setShaderInfo(svBlur, w, h, filter);
  23779. var svCP = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  23780. var matI = Matrix.TEMP.identity();
  23781. ctx.drawTarget(rt, 0, 0, w, h, matI, svBlur);
  23782. ctx.drawTarget(rt, 0, 0, w, h, matI, svCP);
  23783. }
  23784. }
  23785. class GlowFilter extends Filter {
  23786. constructor(color, blur = 4, offX = 6, offY = 6) {
  23787. super();
  23788. this._elements = new Float32Array(9);
  23789. this._sv_blurInfo1 = new Array(4);
  23790. this._sv_blurInfo2 = [0, 0, 1, 0];
  23791. this._color = new ColorUtils(color);
  23792. this.blur = Math.min(blur, 20);
  23793. this.offX = offX;
  23794. this.offY = offY;
  23795. this._sv_blurInfo1[0] = this._sv_blurInfo1[1] = this.blur;
  23796. this._sv_blurInfo1[2] = offX;
  23797. this._sv_blurInfo1[3] = -offY;
  23798. this._glRender = new GlowFilterGLRender();
  23799. }
  23800. get type() {
  23801. return BlurFilter.GLOW;
  23802. }
  23803. get offY() {
  23804. return this._elements[6];
  23805. }
  23806. set offY(value) {
  23807. this._elements[6] = value;
  23808. this._sv_blurInfo1[3] = -value;
  23809. }
  23810. get offX() {
  23811. return this._elements[5];
  23812. }
  23813. set offX(value) {
  23814. this._elements[5] = value;
  23815. this._sv_blurInfo1[2] = value;
  23816. }
  23817. getColor() {
  23818. return this._color.arrColor;
  23819. }
  23820. get blur() {
  23821. return this._elements[4];
  23822. }
  23823. set blur(value) {
  23824. this._elements[4] = value;
  23825. this._sv_blurInfo1[0] = this._sv_blurInfo1[1] = value;
  23826. }
  23827. getColorNative() {
  23828. if (!this._color_native) {
  23829. this._color_native = new Float32Array(4);
  23830. }
  23831. var color = this.getColor();
  23832. this._color_native[0] = color[0];
  23833. this._color_native[1] = color[1];
  23834. this._color_native[2] = color[2];
  23835. this._color_native[3] = color[3];
  23836. return this._color_native;
  23837. }
  23838. getBlurInfo1Native() {
  23839. if (!this._blurInof1_native) {
  23840. this._blurInof1_native = new Float32Array(4);
  23841. }
  23842. this._blurInof1_native[0] = this._blurInof1_native[1] = this.blur;
  23843. this._blurInof1_native[2] = this.offX;
  23844. this._blurInof1_native[3] = this.offY;
  23845. return this._blurInof1_native;
  23846. }
  23847. getBlurInfo2Native() {
  23848. if (!this._blurInof2_native) {
  23849. this._blurInof2_native = new Float32Array(4);
  23850. }
  23851. this._blurInof2_native[2] = 1;
  23852. return this._blurInof2_native;
  23853. }
  23854. }
  23855. class GlowFilterSetter extends FilterSetterBase {
  23856. constructor() {
  23857. super();
  23858. this._color = "#ff0000";
  23859. this._blur = 4;
  23860. this._offX = 6;
  23861. this._offY = 6;
  23862. this._filter = new GlowFilter(this._color);
  23863. }
  23864. buildFilter() {
  23865. this._filter = new GlowFilter(this.color, this.blur, this.offX, this.offY);
  23866. super.buildFilter();
  23867. }
  23868. get color() {
  23869. return this._color;
  23870. }
  23871. set color(value) {
  23872. this._color = value;
  23873. this.paramChanged();
  23874. }
  23875. get blur() {
  23876. return this._blur;
  23877. }
  23878. set blur(value) {
  23879. this._blur = value;
  23880. this.paramChanged();
  23881. }
  23882. get offX() {
  23883. return this._offX;
  23884. }
  23885. set offX(value) {
  23886. this._offX = value;
  23887. this.paramChanged();
  23888. }
  23889. get offY() {
  23890. return this._offY;
  23891. }
  23892. set offY(value) {
  23893. this._offY = value;
  23894. this.paramChanged();
  23895. }
  23896. }
  23897. class KeyLocation {
  23898. }
  23899. KeyLocation.STANDARD = 0;
  23900. KeyLocation.LEFT = 1;
  23901. KeyLocation.RIGHT = 2;
  23902. KeyLocation.NUM_PAD = 3;
  23903. class Keyboard {
  23904. }
  23905. Keyboard.NUMBER_0 = 48;
  23906. Keyboard.NUMBER_1 = 49;
  23907. Keyboard.NUMBER_2 = 50;
  23908. Keyboard.NUMBER_3 = 51;
  23909. Keyboard.NUMBER_4 = 52;
  23910. Keyboard.NUMBER_5 = 53;
  23911. Keyboard.NUMBER_6 = 54;
  23912. Keyboard.NUMBER_7 = 55;
  23913. Keyboard.NUMBER_8 = 56;
  23914. Keyboard.NUMBER_9 = 57;
  23915. Keyboard.A = 65;
  23916. Keyboard.B = 66;
  23917. Keyboard.C = 67;
  23918. Keyboard.D = 68;
  23919. Keyboard.E = 69;
  23920. Keyboard.F = 70;
  23921. Keyboard.G = 71;
  23922. Keyboard.H = 72;
  23923. Keyboard.I = 73;
  23924. Keyboard.J = 74;
  23925. Keyboard.K = 75;
  23926. Keyboard.L = 76;
  23927. Keyboard.M = 77;
  23928. Keyboard.N = 78;
  23929. Keyboard.O = 79;
  23930. Keyboard.P = 80;
  23931. Keyboard.Q = 81;
  23932. Keyboard.R = 82;
  23933. Keyboard.S = 83;
  23934. Keyboard.T = 84;
  23935. Keyboard.U = 85;
  23936. Keyboard.V = 86;
  23937. Keyboard.W = 87;
  23938. Keyboard.X = 88;
  23939. Keyboard.Y = 89;
  23940. Keyboard.Z = 90;
  23941. Keyboard.F1 = 112;
  23942. Keyboard.F2 = 113;
  23943. Keyboard.F3 = 114;
  23944. Keyboard.F4 = 115;
  23945. Keyboard.F5 = 116;
  23946. Keyboard.F6 = 117;
  23947. Keyboard.F7 = 118;
  23948. Keyboard.F8 = 119;
  23949. Keyboard.F9 = 120;
  23950. Keyboard.F10 = 121;
  23951. Keyboard.F11 = 122;
  23952. Keyboard.F12 = 123;
  23953. Keyboard.F13 = 124;
  23954. Keyboard.F14 = 125;
  23955. Keyboard.F15 = 126;
  23956. Keyboard.NUMPAD = 21;
  23957. Keyboard.NUMPAD_0 = 96;
  23958. Keyboard.NUMPAD_1 = 97;
  23959. Keyboard.NUMPAD_2 = 98;
  23960. Keyboard.NUMPAD_3 = 99;
  23961. Keyboard.NUMPAD_4 = 100;
  23962. Keyboard.NUMPAD_5 = 101;
  23963. Keyboard.NUMPAD_6 = 102;
  23964. Keyboard.NUMPAD_7 = 103;
  23965. Keyboard.NUMPAD_8 = 104;
  23966. Keyboard.NUMPAD_9 = 105;
  23967. Keyboard.NUMPAD_ADD = 107;
  23968. Keyboard.NUMPAD_DECIMAL = 110;
  23969. Keyboard.NUMPAD_DIVIDE = 111;
  23970. Keyboard.NUMPAD_ENTER = 108;
  23971. Keyboard.NUMPAD_MULTIPLY = 106;
  23972. Keyboard.NUMPAD_SUBTRACT = 109;
  23973. Keyboard.SEMICOLON = 186;
  23974. Keyboard.EQUAL = 187;
  23975. Keyboard.COMMA = 188;
  23976. Keyboard.MINUS = 189;
  23977. Keyboard.PERIOD = 190;
  23978. Keyboard.SLASH = 191;
  23979. Keyboard.BACKQUOTE = 192;
  23980. Keyboard.LEFTBRACKET = 219;
  23981. Keyboard.BACKSLASH = 220;
  23982. Keyboard.RIGHTBRACKET = 221;
  23983. Keyboard.QUOTE = 222;
  23984. Keyboard.ALTERNATE = 18;
  23985. Keyboard.BACKSPACE = 8;
  23986. Keyboard.CAPS_LOCK = 20;
  23987. Keyboard.COMMAND = 15;
  23988. Keyboard.CONTROL = 17;
  23989. Keyboard.DELETE = 46;
  23990. Keyboard.ENTER = 13;
  23991. Keyboard.ESCAPE = 27;
  23992. Keyboard.PAGE_UP = 33;
  23993. Keyboard.PAGE_DOWN = 34;
  23994. Keyboard.END = 35;
  23995. Keyboard.HOME = 36;
  23996. Keyboard.LEFT = 37;
  23997. Keyboard.UP = 38;
  23998. Keyboard.RIGHT = 39;
  23999. Keyboard.DOWN = 40;
  24000. Keyboard.SHIFT = 16;
  24001. Keyboard.SPACE = 32;
  24002. Keyboard.TAB = 9;
  24003. Keyboard.INSERT = 45;
  24004. class CommandEncoder {
  24005. constructor(layagl, reserveSize, adjustSize, isSyncToRenderThread) {
  24006. this._idata = [];
  24007. }
  24008. getArrayData() {
  24009. return this._idata;
  24010. }
  24011. getPtrID() {
  24012. return 0;
  24013. }
  24014. beginEncoding() {
  24015. }
  24016. endEncoding() {
  24017. }
  24018. clearEncoding() {
  24019. this._idata.length = 0;
  24020. }
  24021. getCount() {
  24022. return this._idata.length;
  24023. }
  24024. add_ShaderValue(o) {
  24025. this._idata.push(o);
  24026. }
  24027. addShaderUniform(one) {
  24028. this.add_ShaderValue(one);
  24029. }
  24030. }
  24031. class LayaGLRunner {
  24032. static uploadShaderUniforms(layaGL, commandEncoder, shaderData, uploadUnTexture) {
  24033. var data = shaderData._data;
  24034. var shaderUniform = commandEncoder.getArrayData();
  24035. var shaderCall = 0;
  24036. for (var i = 0, n = shaderUniform.length; i < n; i++) {
  24037. var one = shaderUniform[i];
  24038. if (uploadUnTexture || one.textureID !== -1) {
  24039. var value = data[one.dataOffset];
  24040. if (value != null)
  24041. shaderCall += one.fun.call(one.caller, one, value);
  24042. }
  24043. }
  24044. return shaderCall;
  24045. }
  24046. static uploadCustomUniform(layaGL, custom, index, data) {
  24047. var shaderCall = 0;
  24048. var one = custom[index];
  24049. if (one && data != null)
  24050. shaderCall += one.fun.call(one.caller, one, data);
  24051. return shaderCall;
  24052. }
  24053. static uploadShaderUniformsForNative(layaGL, commandEncoder, shaderData) {
  24054. return LayaGL.instance.uploadShaderUniforms(commandEncoder, shaderData._data, shaderData._runtimeCopyValues.length > 0 ? LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_DATA : LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_ID);
  24055. }
  24056. }
  24057. class QuickTestTool {
  24058. constructor() {
  24059. }
  24060. static getMCDName(type) {
  24061. return QuickTestTool._typeToNameDic[type];
  24062. }
  24063. static showRenderTypeInfo(type, force = false) {
  24064. if (!force && QuickTestTool.showedDic[type])
  24065. return;
  24066. QuickTestTool.showedDic[type] = true;
  24067. if (!QuickTestTool._rendertypeToStrDic[type]) {
  24068. var arr = [];
  24069. var tType;
  24070. tType = 1;
  24071. while (tType <= type) {
  24072. if (tType & type) {
  24073. arr.push(QuickTestTool.getMCDName(tType & type));
  24074. }
  24075. tType = tType << 1;
  24076. }
  24077. QuickTestTool._rendertypeToStrDic[type] = arr.join(",");
  24078. }
  24079. console.log("cmd:", QuickTestTool._rendertypeToStrDic[type]);
  24080. }
  24081. static __init__() {
  24082. QuickTestTool._typeToNameDic[SpriteConst.ALPHA] = "ALPHA";
  24083. QuickTestTool._typeToNameDic[SpriteConst.TRANSFORM] = "TRANSFORM";
  24084. QuickTestTool._typeToNameDic[SpriteConst.TEXTURE] = "TEXTURE";
  24085. QuickTestTool._typeToNameDic[SpriteConst.GRAPHICS] = "GRAPHICS";
  24086. QuickTestTool._typeToNameDic[SpriteConst.ONECHILD] = "ONECHILD";
  24087. QuickTestTool._typeToNameDic[SpriteConst.CHILDS] = "CHILDS";
  24088. QuickTestTool._typeToNameDic[SpriteConst.TRANSFORM | SpriteConst.ALPHA] = "TRANSFORM|ALPHA";
  24089. QuickTestTool._typeToNameDic[SpriteConst.CANVAS] = "CANVAS";
  24090. QuickTestTool._typeToNameDic[SpriteConst.BLEND] = "BLEND";
  24091. QuickTestTool._typeToNameDic[SpriteConst.FILTERS] = "FILTERS";
  24092. QuickTestTool._typeToNameDic[SpriteConst.MASK] = "MASK";
  24093. QuickTestTool._typeToNameDic[SpriteConst.CLIP] = "CLIP";
  24094. QuickTestTool._typeToNameDic[SpriteConst.LAYAGL3D] = "LAYAGL3D";
  24095. }
  24096. render(context, x, y) {
  24097. QuickTestTool._addType(this._renderType);
  24098. QuickTestTool.showRenderTypeInfo(this._renderType);
  24099. RenderSprite.renders[this._renderType]._fun(this, context, x + this._x, y + this._y);
  24100. this._repaint = 0;
  24101. }
  24102. _stageRender(context, x, y) {
  24103. QuickTestTool._countStart();
  24104. QuickTestTool._PreStageRender.call(ILaya.stage, context, x, y);
  24105. QuickTestTool._countEnd();
  24106. }
  24107. static _countStart() {
  24108. var key;
  24109. for (key in QuickTestTool._countDic) {
  24110. QuickTestTool._countDic[key] = 0;
  24111. }
  24112. }
  24113. static _countEnd() {
  24114. QuickTestTool._i++;
  24115. if (QuickTestTool._i > 60) {
  24116. QuickTestTool.showCountInfo();
  24117. QuickTestTool._i = 0;
  24118. }
  24119. }
  24120. static _addType(type) {
  24121. if (!QuickTestTool._countDic[type]) {
  24122. QuickTestTool._countDic[type] = 1;
  24123. }
  24124. else {
  24125. QuickTestTool._countDic[type] += 1;
  24126. }
  24127. }
  24128. static showCountInfo() {
  24129. console.log("===================");
  24130. var key;
  24131. for (key in QuickTestTool._countDic) {
  24132. console.log("count:" + QuickTestTool._countDic[key]);
  24133. QuickTestTool.showRenderTypeInfo(key, true);
  24134. }
  24135. }
  24136. static enableQuickTest() {
  24137. QuickTestTool.__init__();
  24138. Sprite["prototype"]["render"] = QuickTestTool["prototype"]["render"];
  24139. QuickTestTool._PreStageRender = Stage["prototype"]["render"];
  24140. Stage["prototype"]["render"] = QuickTestTool["prototype"]["_stageRender"];
  24141. }
  24142. }
  24143. QuickTestTool.showedDic = {};
  24144. QuickTestTool._rendertypeToStrDic = {};
  24145. QuickTestTool._typeToNameDic = {};
  24146. QuickTestTool._countDic = {};
  24147. QuickTestTool._i = 0;
  24148. class Sound extends EventDispatcher {
  24149. load(url) {
  24150. }
  24151. play(startTime = 0, loops = 0) {
  24152. return null;
  24153. }
  24154. get duration() {
  24155. return 0;
  24156. }
  24157. dispose() {
  24158. }
  24159. }
  24160. class SoundNode extends Sprite {
  24161. constructor() {
  24162. super();
  24163. this.visible = false;
  24164. this.on(Event.ADDED, this, this._onParentChange);
  24165. this.on(Event.REMOVED, this, this._onParentChange);
  24166. }
  24167. _onParentChange() {
  24168. this.target = this.parent;
  24169. }
  24170. play(loops = 1, complete = null) {
  24171. if (isNaN(loops)) {
  24172. loops = 1;
  24173. }
  24174. if (!this.url)
  24175. return;
  24176. this.stop();
  24177. this._channel = SoundManager.playSound(this.url, loops, complete);
  24178. }
  24179. stop() {
  24180. if (this._channel && !this._channel.isStopped) {
  24181. this._channel.stop();
  24182. }
  24183. this._channel = null;
  24184. }
  24185. _setPlayAction(tar, event, action, add = true) {
  24186. if (!this[action])
  24187. return;
  24188. if (!tar)
  24189. return;
  24190. if (add) {
  24191. tar.on(event, this, this[action]);
  24192. }
  24193. else {
  24194. tar.off(event, this, this[action]);
  24195. }
  24196. }
  24197. _setPlayActions(tar, events, action, add = true) {
  24198. if (!tar)
  24199. return;
  24200. if (!events)
  24201. return;
  24202. var eventArr = events.split(",");
  24203. var i, len;
  24204. len = eventArr.length;
  24205. for (i = 0; i < len; i++) {
  24206. this._setPlayAction(tar, eventArr[i], action, add);
  24207. }
  24208. }
  24209. set playEvent(events) {
  24210. this._playEvents = events;
  24211. if (!events)
  24212. return;
  24213. if (this._tar) {
  24214. this._setPlayActions(this._tar, events, "play");
  24215. }
  24216. }
  24217. set target(tar) {
  24218. if (this._tar) {
  24219. this._setPlayActions(this._tar, this._playEvents, "play", false);
  24220. this._setPlayActions(this._tar, this._stopEvents, "stop", false);
  24221. }
  24222. this._tar = tar;
  24223. if (this._tar) {
  24224. this._setPlayActions(this._tar, this._playEvents, "play", true);
  24225. this._setPlayActions(this._tar, this._stopEvents, "stop", true);
  24226. }
  24227. }
  24228. set stopEvent(events) {
  24229. this._stopEvents = events;
  24230. if (!events)
  24231. return;
  24232. if (this._tar) {
  24233. this._setPlayActions(this._tar, events, "stop");
  24234. }
  24235. }
  24236. }
  24237. class ResourceVersion {
  24238. static enable(manifestFile, callback, type = 2) {
  24239. ResourceVersion.type = type;
  24240. ILaya.loader.load(manifestFile, Handler.create(null, ResourceVersion.onManifestLoaded, [callback]), null, Loader.JSON);
  24241. }
  24242. static onManifestLoaded(callback, data) {
  24243. ResourceVersion.manifest = data;
  24244. URL.customFormat = ResourceVersion.addVersionPrefix;
  24245. callback.run();
  24246. if (!data) {
  24247. console.warn("资源版本清单文件不存在,不使用资源版本管理。忽略ERR_FILE_NOT_FOUND错误。");
  24248. }
  24249. }
  24250. static addVersionPrefix(originURL) {
  24251. originURL = URL.getAdptedFilePath(originURL);
  24252. if (ResourceVersion.manifest && ResourceVersion.manifest[originURL]) {
  24253. if (ResourceVersion.type == ResourceVersion.FILENAME_VERSION)
  24254. return ResourceVersion.manifest[originURL];
  24255. return ResourceVersion.manifest[originURL] + "/" + originURL;
  24256. }
  24257. return originURL;
  24258. }
  24259. }
  24260. ResourceVersion.FOLDER_VERSION = 1;
  24261. ResourceVersion.FILENAME_VERSION = 2;
  24262. ResourceVersion.type = ResourceVersion.FOLDER_VERSION;
  24263. class Socket extends EventDispatcher {
  24264. constructor(host = null, port = 0, byteClass = null, protocols = null) {
  24265. super();
  24266. this.disableInput = false;
  24267. this.protocols = [];
  24268. this._byteClass = byteClass ? byteClass : Byte;
  24269. this.protocols = protocols;
  24270. this.endian = Socket.BIG_ENDIAN;
  24271. if (host && port > 0 && port < 65535)
  24272. this.connect(host, port);
  24273. }
  24274. get input() {
  24275. return this._input;
  24276. }
  24277. get output() {
  24278. return this._output;
  24279. }
  24280. get connected() {
  24281. return this._connected;
  24282. }
  24283. get endian() {
  24284. return this._endian;
  24285. }
  24286. set endian(value) {
  24287. this._endian = value;
  24288. if (this._input != null)
  24289. this._input.endian = value;
  24290. if (this._output != null)
  24291. this._output.endian = value;
  24292. }
  24293. connect(host, port) {
  24294. var url = "ws://" + host + ":" + port;
  24295. this.connectByUrl(url);
  24296. }
  24297. connectByUrl(url) {
  24298. if (this._socket != null)
  24299. this.close();
  24300. this._socket && this.cleanSocket();
  24301. if (!this.protocols || this.protocols.length == 0) {
  24302. this._socket = new Browser.window.WebSocket(url);
  24303. }
  24304. else {
  24305. this._socket = new Browser.window.WebSocket(url, this.protocols);
  24306. }
  24307. this._socket.binaryType = "arraybuffer";
  24308. this._output = new this._byteClass();
  24309. this._output.endian = this.endian;
  24310. this._input = new this._byteClass();
  24311. this._input.endian = this.endian;
  24312. this._addInputPosition = 0;
  24313. this._socket.onopen = (e) => {
  24314. this._onOpen(e);
  24315. };
  24316. this._socket.onmessage = (msg) => {
  24317. this._onMessage(msg);
  24318. };
  24319. this._socket.onclose = (e) => {
  24320. this._onClose(e);
  24321. };
  24322. this._socket.onerror = (e) => {
  24323. this._onError(e);
  24324. };
  24325. }
  24326. cleanSocket() {
  24327. this.close();
  24328. this._connected = false;
  24329. this._socket.onopen = null;
  24330. this._socket.onmessage = null;
  24331. this._socket.onclose = null;
  24332. this._socket.onerror = null;
  24333. this._socket = null;
  24334. }
  24335. close() {
  24336. if (this._socket != null) {
  24337. try {
  24338. this._socket.close();
  24339. }
  24340. catch (e) {
  24341. }
  24342. }
  24343. }
  24344. _onOpen(e) {
  24345. this._connected = true;
  24346. this.event(Event.OPEN, e);
  24347. }
  24348. _onMessage(msg) {
  24349. if (!msg || !msg.data)
  24350. return;
  24351. var data = msg.data;
  24352. if (this.disableInput && data) {
  24353. this.event(Event.MESSAGE, data);
  24354. return;
  24355. }
  24356. if (this._input.length > 0 && this._input.bytesAvailable < 1) {
  24357. this._input.clear();
  24358. this._addInputPosition = 0;
  24359. }
  24360. var pre = this._input.pos;
  24361. !this._addInputPosition && (this._addInputPosition = 0);
  24362. this._input.pos = this._addInputPosition;
  24363. if (data) {
  24364. if (typeof (data) == 'string') {
  24365. this._input.writeUTFBytes(data);
  24366. }
  24367. else {
  24368. this._input.writeArrayBuffer(data);
  24369. }
  24370. this._addInputPosition = this._input.pos;
  24371. this._input.pos = pre;
  24372. }
  24373. this.event(Event.MESSAGE, data);
  24374. }
  24375. _onClose(e) {
  24376. this._connected = false;
  24377. this.event(Event.CLOSE, e);
  24378. }
  24379. _onError(e) {
  24380. this.event(Event.ERROR, e);
  24381. }
  24382. send(data) {
  24383. this._socket.send(data);
  24384. }
  24385. flush() {
  24386. if (this._output && this._output.length > 0) {
  24387. var evt;
  24388. try {
  24389. this._socket && this._socket.send(this._output.__getBuffer().slice(0, this._output.length));
  24390. }
  24391. catch (e) {
  24392. evt = e;
  24393. }
  24394. this._output.endian = this.endian;
  24395. this._output.clear();
  24396. if (evt)
  24397. this.event(Event.ERROR, evt);
  24398. }
  24399. }
  24400. }
  24401. Socket.LITTLE_ENDIAN = "littleEndian";
  24402. Socket.BIG_ENDIAN = "bigEndian";
  24403. class System {
  24404. static changeDefinition(name, classObj) {
  24405. window.Laya[name] = classObj;
  24406. var str = name + "=classObj";
  24407. window['eval'](str);
  24408. }
  24409. }
  24410. class HTMLChar {
  24411. constructor() {
  24412. this.reset();
  24413. }
  24414. setData(char, w, h, style) {
  24415. this.char = char;
  24416. this.charNum = char.charCodeAt(0);
  24417. this.x = this.y = 0;
  24418. this.width = w;
  24419. this.height = h;
  24420. this.style = style;
  24421. this.isWord = !HTMLChar._isWordRegExp.test(char);
  24422. return this;
  24423. }
  24424. reset() {
  24425. this.x = this.y = this.width = this.height = 0;
  24426. this.isWord = false;
  24427. this.char = null;
  24428. this.charNum = 0;
  24429. this.style = null;
  24430. return this;
  24431. }
  24432. recover() {
  24433. Pool.recover("HTMLChar", this.reset());
  24434. }
  24435. static create() {
  24436. return Pool.getItemByClass("HTMLChar", HTMLChar);
  24437. }
  24438. _isChar() {
  24439. return true;
  24440. }
  24441. _getCSSStyle() {
  24442. return this.style;
  24443. }
  24444. }
  24445. HTMLChar._isWordRegExp = new RegExp("[\\w\.]", "");
  24446. class Log {
  24447. static enable() {
  24448. if (!Log._logdiv) {
  24449. Log._logdiv = Browser.createElement('div');
  24450. 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%;";
  24451. Browser.document.body.appendChild(Log._logdiv);
  24452. Log._btn = Browser.createElement("button");
  24453. Log._btn.innerText = "Hide";
  24454. Log._btn.style.cssText = "z-index:1000001;position: absolute;left:10px;top:10px;";
  24455. Log._btn.onclick = Log.toggle;
  24456. Browser.document.body.appendChild(Log._btn);
  24457. }
  24458. }
  24459. static toggle() {
  24460. var style = Log._logdiv.style;
  24461. if (style.display === "") {
  24462. Log._btn.innerText = "Show";
  24463. style.display = "none";
  24464. }
  24465. else {
  24466. Log._btn.innerText = "Hide";
  24467. style.display = "";
  24468. }
  24469. }
  24470. static print(value) {
  24471. if (Log._logdiv) {
  24472. if (Log._count >= Log.maxCount)
  24473. Log.clear();
  24474. Log._count++;
  24475. Log._logdiv.innerText += value + "\n";
  24476. if (Log.autoScrollToBottom) {
  24477. if (Log._logdiv.scrollHeight - Log._logdiv.scrollTop - Log._logdiv.clientHeight < 50) {
  24478. Log._logdiv.scrollTop = Log._logdiv.scrollHeight;
  24479. }
  24480. }
  24481. }
  24482. }
  24483. static clear() {
  24484. Log._logdiv.innerText = "";
  24485. Log._count = 0;
  24486. }
  24487. }
  24488. Log._count = 0;
  24489. Log.maxCount = 50;
  24490. Log.autoScrollToBottom = true;
  24491. let DATANUM = 300;
  24492. class PerfData {
  24493. constructor(id, color, name, scale) {
  24494. this.scale = 1.0;
  24495. this.datas = new Array(DATANUM);
  24496. this.datapos = 0;
  24497. this.id = id;
  24498. this.color = color;
  24499. this.name = name;
  24500. this.scale = scale;
  24501. }
  24502. addData(v) {
  24503. this.datas[this.datapos] = v;
  24504. this.datapos++;
  24505. this.datapos %= DATANUM;
  24506. }
  24507. }
  24508. class PerfHUD extends Sprite {
  24509. constructor() {
  24510. super();
  24511. this.datas = [];
  24512. this.xdata = new Array(PerfHUD.DATANUM);
  24513. this.ydata = new Array(PerfHUD.DATANUM);
  24514. this.hud_width = 800;
  24515. this.hud_height = 200;
  24516. this.gMinV = 0;
  24517. this.gMaxV = 100;
  24518. this.textSpace = 40;
  24519. this.sttm = 0;
  24520. PerfHUD.inst = this;
  24521. this._renderType |= SpriteConst.CUSTOM;
  24522. this._setRenderType(this._renderType);
  24523. this._setCustomRender();
  24524. this.addDataDef(0, 0xffffff, 'frame', 1.0);
  24525. this.addDataDef(1, 0x00ff00, 'update', 1.0);
  24526. this.addDataDef(2, 0xff0000, 'flush', 1.0);
  24527. PerfHUD._now = performance ? performance.now.bind(performance) : Date.now;
  24528. }
  24529. now() {
  24530. return PerfHUD._now();
  24531. }
  24532. start() {
  24533. this.sttm = PerfHUD._now();
  24534. }
  24535. end(i) {
  24536. var dt = PerfHUD._now() - this.sttm;
  24537. this.updateValue(i, dt);
  24538. }
  24539. config(w, h) {
  24540. this.hud_width = w;
  24541. this.hud_height = h;
  24542. }
  24543. addDataDef(id, color, name, scale) {
  24544. this.datas[id] = new PerfData(id, color, name, scale);
  24545. }
  24546. updateValue(id, v) {
  24547. this.datas[id].addData(v);
  24548. }
  24549. v2y(v) {
  24550. var bb = this._y + this.hud_height * (1 - (v - this.gMinV) / this.gMaxV);
  24551. return this._y + this.hud_height * (1 - (v - this.gMinV) / this.gMaxV);
  24552. }
  24553. drawHLine(ctx, v, color, text) {
  24554. var sx = this._x;
  24555. var ex = this._x + this.hud_width;
  24556. var sy = this.v2y(v);
  24557. ctx.fillText(text, sx, sy - 6, null, 'green', null);
  24558. sx += this.textSpace;
  24559. ctx.fillStyle = color;
  24560. ctx.fillRect(sx, sy, this._x + this.hud_width, 1, null);
  24561. }
  24562. customRender(ctx, x, y) {
  24563. var now = performance.now();
  24564. if (PerfHUD._lastTm <= 0)
  24565. PerfHUD._lastTm = now;
  24566. this.updateValue(0, now - PerfHUD._lastTm);
  24567. PerfHUD._lastTm = now;
  24568. ctx.save();
  24569. ctx.fillRect(this._x, this._y, this.hud_width, this.hud_height + 4, '#000000cc');
  24570. ctx.globalAlpha = 0.9;
  24571. this.drawHLine(ctx, 0, 'green', ' 0');
  24572. this.drawHLine(ctx, 10, 'green', ' 10');
  24573. this.drawHLine(ctx, 16.667, 'red', ' ');
  24574. this.drawHLine(ctx, 20, 'green', '50|20');
  24575. this.drawHLine(ctx, 16.667 * 2, 'yellow', '');
  24576. this.drawHLine(ctx, 16.667 * 3, 'yellow', '');
  24577. this.drawHLine(ctx, 16.667 * 4, 'yellow', '');
  24578. this.drawHLine(ctx, 50, 'green', '20|50');
  24579. this.drawHLine(ctx, 100, 'green', '10|100');
  24580. for (var di = 0, sz = this.datas.length; di < sz; di++) {
  24581. var cd = this.datas[di];
  24582. if (!cd)
  24583. continue;
  24584. var dtlen = cd.datas.length;
  24585. var dx = (this.hud_width - this.textSpace) / dtlen;
  24586. var cx = cd.datapos;
  24587. var _cx = this._x + this.textSpace;
  24588. ctx.fillStyle = cd.color;
  24589. for (var dtsz = dtlen; cx < dtsz; cx++) {
  24590. var sty = this.v2y(cd.datas[cx] * cd.scale);
  24591. ctx.fillRect(_cx, sty, dx, this.hud_height + this._y - sty, null);
  24592. _cx += dx;
  24593. }
  24594. for (cx = 0; cx < cd.datapos; cx++) {
  24595. sty = this.v2y(cd.datas[cx] * cd.scale);
  24596. ctx.fillRect(_cx, sty, dx, this.hud_height + this._y - sty, null);
  24597. _cx += dx;
  24598. }
  24599. }
  24600. ctx.restore();
  24601. }
  24602. }
  24603. PerfHUD._lastTm = 0;
  24604. PerfHUD._now = null;
  24605. PerfHUD.DATANUM = 300;
  24606. PerfHUD.drawTexTm = 0;
  24607. class PoolCache {
  24608. constructor() {
  24609. this.maxCount = 1000;
  24610. }
  24611. getCacheList() {
  24612. return Pool.getPoolBySign(this.sign);
  24613. }
  24614. tryDispose(force) {
  24615. var list;
  24616. list = Pool.getPoolBySign(this.sign);
  24617. if (list.length > this.maxCount) {
  24618. list.splice(this.maxCount, list.length - this.maxCount);
  24619. }
  24620. }
  24621. static addPoolCacheManager(sign, maxCount = 100) {
  24622. var cache;
  24623. cache = new PoolCache();
  24624. cache.sign = sign;
  24625. cache.maxCount = maxCount;
  24626. CacheManger.regCacheByFunction(Utils.bind(cache.tryDispose, cache), Utils.bind(cache.getCacheList, cache));
  24627. }
  24628. }
  24629. class TimeLine extends EventDispatcher {
  24630. constructor() {
  24631. super(...arguments);
  24632. this._tweenDic = {};
  24633. this._tweenDataList = [];
  24634. this._currTime = 0;
  24635. this._lastTime = 0;
  24636. this._startTime = 0;
  24637. this._index = 0;
  24638. this._gidIndex = 0;
  24639. this._firstTweenDic = {};
  24640. this._startTimeSort = false;
  24641. this._endTimeSort = false;
  24642. this._loopKey = false;
  24643. this.scale = 1;
  24644. this._frameRate = 60;
  24645. this._frameIndex = 0;
  24646. this._total = 0;
  24647. }
  24648. static to(target, props, duration, ease = null, offset = 0) {
  24649. return (new TimeLine()).to(target, props, duration, ease, offset);
  24650. }
  24651. static from(target, props, duration, ease = null, offset = 0) {
  24652. return (new TimeLine()).from(target, props, duration, ease, offset);
  24653. }
  24654. to(target, props, duration, ease = null, offset = 0) {
  24655. return this._create(target, props, duration, ease, offset, true);
  24656. }
  24657. from(target, props, duration, ease = null, offset = 0) {
  24658. return this._create(target, props, duration, ease, offset, false);
  24659. }
  24660. _create(target, props, duration, ease, offset, isTo) {
  24661. var tTweenData = Pool.getItemByClass("tweenData", tweenData);
  24662. tTweenData.isTo = isTo;
  24663. tTweenData.type = 0;
  24664. tTweenData.target = target;
  24665. tTweenData.duration = duration;
  24666. tTweenData.data = props;
  24667. tTweenData.startTime = this._startTime + offset;
  24668. tTweenData.endTime = tTweenData.startTime + tTweenData.duration;
  24669. tTweenData.ease = ease;
  24670. this._startTime = Math.max(tTweenData.endTime, this._startTime);
  24671. this._tweenDataList.push(tTweenData);
  24672. this._startTimeSort = true;
  24673. this._endTimeSort = true;
  24674. return this;
  24675. }
  24676. addLabel(label, offset) {
  24677. var tTweenData = Pool.getItemByClass("tweenData", tweenData);
  24678. tTweenData.type = 1;
  24679. tTweenData.data = label;
  24680. tTweenData.endTime = tTweenData.startTime = this._startTime + offset;
  24681. this._labelDic || (this._labelDic = {});
  24682. this._labelDic[label] = tTweenData;
  24683. this._tweenDataList.push(tTweenData);
  24684. return this;
  24685. }
  24686. removeLabel(label) {
  24687. if (this._labelDic && this._labelDic[label]) {
  24688. var tTweenData = this._labelDic[label];
  24689. if (tTweenData) {
  24690. var tIndex = this._tweenDataList.indexOf(tTweenData);
  24691. if (tIndex > -1) {
  24692. this._tweenDataList.splice(tIndex, 1);
  24693. }
  24694. }
  24695. delete this._labelDic[label];
  24696. }
  24697. }
  24698. gotoTime(time) {
  24699. if (this._tweenDataList == null || this._tweenDataList.length == 0)
  24700. return;
  24701. var tTween;
  24702. var tObject;
  24703. for (var p in this._firstTweenDic) {
  24704. tObject = this._firstTweenDic[p];
  24705. if (tObject) {
  24706. for (var tDataP in tObject) {
  24707. if (tDataP in tObject.diyTarget) {
  24708. tObject.diyTarget[tDataP] = tObject[tDataP];
  24709. }
  24710. }
  24711. }
  24712. }
  24713. for (p in this._tweenDic) {
  24714. tTween = this._tweenDic[p];
  24715. tTween.clear();
  24716. delete this._tweenDic[p];
  24717. }
  24718. this._index = 0;
  24719. this._gidIndex = 0;
  24720. this._currTime = time;
  24721. this._lastTime = Browser.now();
  24722. var tTweenDataCopyList;
  24723. if (this._endTweenDataList == null || this._endTimeSort) {
  24724. this._endTimeSort = false;
  24725. this._endTweenDataList = tTweenDataCopyList = this._tweenDataList.concat();
  24726. function Compare(paraA, paraB) {
  24727. if (paraA.endTime > paraB.endTime) {
  24728. return 1;
  24729. }
  24730. else if (paraA.endTime < paraB.endTime) {
  24731. return -1;
  24732. }
  24733. else {
  24734. return 0;
  24735. }
  24736. }
  24737. tTweenDataCopyList.sort(Compare);
  24738. }
  24739. else {
  24740. tTweenDataCopyList = this._endTweenDataList;
  24741. }
  24742. var tTweenData;
  24743. for (var i = 0, n = tTweenDataCopyList.length; i < n; i++) {
  24744. tTweenData = tTweenDataCopyList[i];
  24745. if (tTweenData.type == 0) {
  24746. if (time >= tTweenData.endTime) {
  24747. this._index = Math.max(this._index, i + 1);
  24748. var props = tTweenData.data;
  24749. if (tTweenData.isTo) {
  24750. for (var tP in props) {
  24751. tTweenData.target[tP] = props[tP];
  24752. }
  24753. }
  24754. }
  24755. else {
  24756. break;
  24757. }
  24758. }
  24759. }
  24760. for (i = 0, n = this._tweenDataList.length; i < n; i++) {
  24761. tTweenData = this._tweenDataList[i];
  24762. if (tTweenData.type == 0) {
  24763. if (time >= tTweenData.startTime && time < tTweenData.endTime) {
  24764. this._index = Math.max(this._index, i + 1);
  24765. this._gidIndex++;
  24766. tTween = Pool.getItemByClass("tween", Tween);
  24767. tTween._create(tTweenData.target, tTweenData.data, tTweenData.duration, tTweenData.ease, Handler.create(this, this._animComplete, [this._gidIndex]), 0, false, tTweenData.isTo, true, false);
  24768. tTween.setStartTime(this._currTime - (time - tTweenData.startTime));
  24769. tTween._updateEase(this._currTime);
  24770. tTween.gid = this._gidIndex;
  24771. this._tweenDic[this._gidIndex] = tTween;
  24772. }
  24773. }
  24774. }
  24775. }
  24776. gotoLabel(Label) {
  24777. if (this._labelDic == null)
  24778. return;
  24779. var tLabelData = this._labelDic[Label];
  24780. if (tLabelData)
  24781. this.gotoTime(tLabelData.startTime);
  24782. }
  24783. pause() {
  24784. ILaya.timer.clear(this, this._update);
  24785. }
  24786. resume() {
  24787. this.play(this._currTime, this._loopKey);
  24788. }
  24789. play(timeOrLabel = 0, loop = false) {
  24790. if (!this._tweenDataList)
  24791. return;
  24792. if (this._startTimeSort) {
  24793. this._startTimeSort = false;
  24794. function Compare(paraA, paraB) {
  24795. if (paraA.startTime > paraB.startTime) {
  24796. return 1;
  24797. }
  24798. else if (paraA.startTime < paraB.startTime) {
  24799. return -1;
  24800. }
  24801. else {
  24802. return 0;
  24803. }
  24804. }
  24805. this._tweenDataList.sort(Compare);
  24806. for (var i = 0, n = this._tweenDataList.length; i < n; i++) {
  24807. var tTweenData = this._tweenDataList[i];
  24808. if (tTweenData != null && tTweenData.type == 0) {
  24809. var tTarget = tTweenData.target;
  24810. var gid = (tTarget.$_GID || (tTarget.$_GID = Utils.getGID()));
  24811. var tSrcData = null;
  24812. if (this._firstTweenDic[gid] == null) {
  24813. tSrcData = {};
  24814. tSrcData.diyTarget = tTarget;
  24815. this._firstTweenDic[gid] = tSrcData;
  24816. }
  24817. else {
  24818. tSrcData = this._firstTweenDic[gid];
  24819. }
  24820. for (var p in tTweenData.data) {
  24821. if (tSrcData[p] == null) {
  24822. tSrcData[p] = tTarget[p];
  24823. }
  24824. }
  24825. }
  24826. }
  24827. }
  24828. if (typeof (timeOrLabel) == 'string') {
  24829. this.gotoLabel(timeOrLabel);
  24830. }
  24831. else {
  24832. this.gotoTime(timeOrLabel);
  24833. }
  24834. this._loopKey = loop;
  24835. this._lastTime = Browser.now();
  24836. ILaya.timer.frameLoop(1, this, this._update);
  24837. }
  24838. _update() {
  24839. if (this._currTime >= this._startTime) {
  24840. if (this._loopKey) {
  24841. this._complete();
  24842. if (!this._tweenDataList)
  24843. return;
  24844. this.gotoTime(0);
  24845. }
  24846. else {
  24847. for (var p in this._tweenDic) {
  24848. tTween = this._tweenDic[p];
  24849. tTween.complete();
  24850. }
  24851. this._complete();
  24852. this.pause();
  24853. return;
  24854. }
  24855. }
  24856. var tNow = Browser.now();
  24857. var tFrameTime = tNow - this._lastTime;
  24858. var tCurrTime = this._currTime += tFrameTime * this.scale;
  24859. this._lastTime = tNow;
  24860. for (p in this._tweenDic) {
  24861. tTween = this._tweenDic[p];
  24862. tTween._updateEase(tCurrTime);
  24863. }
  24864. var tTween;
  24865. if (this._tweenDataList.length != 0 && this._index < this._tweenDataList.length) {
  24866. var tTweenData = this._tweenDataList[this._index];
  24867. if (tCurrTime >= tTweenData.startTime) {
  24868. this._index++;
  24869. if (tTweenData.type == 0) {
  24870. this._gidIndex++;
  24871. tTween = Pool.getItemByClass("tween", Tween);
  24872. tTween._create(tTweenData.target, tTweenData.data, tTweenData.duration, tTweenData.ease, Handler.create(this, this._animComplete, [this._gidIndex]), 0, false, tTweenData.isTo, true, false);
  24873. tTween.setStartTime(tCurrTime);
  24874. tTween.gid = this._gidIndex;
  24875. this._tweenDic[this._gidIndex] = tTween;
  24876. tTween._updateEase(tCurrTime);
  24877. }
  24878. else {
  24879. this.event(Event.LABEL, tTweenData.data);
  24880. }
  24881. }
  24882. }
  24883. }
  24884. _animComplete(index) {
  24885. var tTween = this._tweenDic[index];
  24886. if (tTween)
  24887. delete this._tweenDic[index];
  24888. }
  24889. _complete() {
  24890. this.event(Event.COMPLETE);
  24891. }
  24892. get index() {
  24893. return this._frameIndex;
  24894. }
  24895. set index(value) {
  24896. this._frameIndex = value;
  24897. this.gotoTime(this._frameIndex / this._frameRate * 1000);
  24898. }
  24899. get total() {
  24900. this._total = Math.floor(this._startTime / 1000 * this._frameRate);
  24901. return this._total;
  24902. }
  24903. reset() {
  24904. var p;
  24905. if (this._labelDic) {
  24906. for (p in this._labelDic) {
  24907. delete this._labelDic[p];
  24908. }
  24909. }
  24910. var tTween;
  24911. for (p in this._tweenDic) {
  24912. tTween = this._tweenDic[p];
  24913. tTween.clear();
  24914. delete this._tweenDic[p];
  24915. }
  24916. for (p in this._firstTweenDic) {
  24917. delete this._firstTweenDic[p];
  24918. }
  24919. this._endTweenDataList = null;
  24920. if (this._tweenDataList && this._tweenDataList.length) {
  24921. var i, len;
  24922. len = this._tweenDataList.length;
  24923. for (i = 0; i < len; i++) {
  24924. if (this._tweenDataList[i])
  24925. this._tweenDataList[i].destroy();
  24926. }
  24927. }
  24928. this._tweenDataList.length = 0;
  24929. this._currTime = 0;
  24930. this._lastTime = 0;
  24931. this._startTime = 0;
  24932. this._index = 0;
  24933. this._gidIndex = 0;
  24934. this.scale = 1;
  24935. ILaya.timer.clear(this, this._update);
  24936. }
  24937. destroy() {
  24938. this.reset();
  24939. this._labelDic = null;
  24940. this._tweenDic = null;
  24941. this._tweenDataList = null;
  24942. this._firstTweenDic = null;
  24943. }
  24944. }
  24945. class tweenData {
  24946. constructor() {
  24947. this.type = 0;
  24948. this.isTo = true;
  24949. }
  24950. destroy() {
  24951. this.target = null;
  24952. this.ease = null;
  24953. this.data = null;
  24954. this.isTo = true;
  24955. this.type = 0;
  24956. Pool.recover("tweenData", this);
  24957. }
  24958. }
  24959. class ShaderValue {
  24960. constructor() {
  24961. }
  24962. }
  24963. class ArabicReshaper {
  24964. characterMapContains(c) {
  24965. for (var i = 0; i < ArabicReshaper.charsMap.length; ++i) {
  24966. if (ArabicReshaper.charsMap[i][0] === c) {
  24967. return true;
  24968. }
  24969. }
  24970. return false;
  24971. }
  24972. getCharRep(c) {
  24973. for (var i = 0; i < ArabicReshaper.charsMap.length; ++i) {
  24974. if (ArabicReshaper.charsMap[i][0] === c) {
  24975. return ArabicReshaper.charsMap[i];
  24976. }
  24977. }
  24978. return false;
  24979. }
  24980. getCombCharRep(c1, c2) {
  24981. for (var i = 0; i < ArabicReshaper.combCharsMap.length; ++i) {
  24982. if (ArabicReshaper.combCharsMap[i][0][0] === c1 && ArabicReshaper.combCharsMap[i][0][1] === c2) {
  24983. return ArabicReshaper.combCharsMap[i];
  24984. }
  24985. }
  24986. return false;
  24987. }
  24988. isTransparent(c) {
  24989. for (var i = 0; i < ArabicReshaper.transChars.length; ++i) {
  24990. if (ArabicReshaper.transChars[i] === c) {
  24991. return true;
  24992. }
  24993. }
  24994. return false;
  24995. }
  24996. getOriginalCharsFromCode(code) {
  24997. var j;
  24998. for (j = 0; j < ArabicReshaper.charsMap.length; ++j) {
  24999. if (ArabicReshaper.charsMap[j].indexOf(code) > -1) {
  25000. return String.fromCharCode(ArabicReshaper.charsMap[j][0]);
  25001. }
  25002. }
  25003. for (j = 0; j < ArabicReshaper.combCharsMap.length; ++j) {
  25004. if (ArabicReshaper.combCharsMap[j].indexOf(code) > -1) {
  25005. return String.fromCharCode(ArabicReshaper.combCharsMap[j][0][0]) +
  25006. String.fromCharCode(ArabicReshaper.combCharsMap[j][0][1]);
  25007. }
  25008. }
  25009. return String.fromCharCode(code);
  25010. }
  25011. convertArabic(normal) {
  25012. var crep, combcrep, shaped = '';
  25013. for (var i = 0; i < normal.length; ++i) {
  25014. var current = normal.charCodeAt(i);
  25015. if (this.characterMapContains(current)) {
  25016. var prev = null, next = null, prevID = i - 1, nextID = i + 1;
  25017. for (; prevID >= 0; --prevID) {
  25018. if (!this.isTransparent(normal.charCodeAt(prevID))) {
  25019. break;
  25020. }
  25021. }
  25022. prev = (prevID >= 0) ? normal.charCodeAt(prevID) : null;
  25023. crep = prev ? this.getCharRep(prev) : false;
  25024. if (!crep || crep[2] == null && crep[3] == null) {
  25025. prev = null;
  25026. }
  25027. for (; nextID < normal.length; ++nextID) {
  25028. if (!this.isTransparent(normal.charCodeAt(nextID))) {
  25029. break;
  25030. }
  25031. }
  25032. next = (nextID < normal.length) ? normal.charCodeAt(nextID) : null;
  25033. crep = next ? this.getCharRep(next) : false;
  25034. if (!crep || crep[3] == null && crep[4] == null) {
  25035. next = null;
  25036. }
  25037. if (current === 0x0644 && next != null &&
  25038. (next === 0x0622 || next === 0x0623 || next === 0x0625 || next === 0x0627)) {
  25039. combcrep = this.getCombCharRep(current, next);
  25040. if (prev != null) {
  25041. shaped += String.fromCharCode(combcrep[4]);
  25042. }
  25043. else {
  25044. shaped += String.fromCharCode(combcrep[1]);
  25045. }
  25046. ++i;
  25047. continue;
  25048. }
  25049. crep = this.getCharRep(current);
  25050. if (prev != null && next != null && crep[3] != null) {
  25051. shaped += String.fromCharCode(crep[3]);
  25052. continue;
  25053. }
  25054. else if (prev != null && crep[4] != null) {
  25055. shaped += String.fromCharCode(crep[4]);
  25056. continue;
  25057. }
  25058. else if (next != null && crep[2] != null) {
  25059. shaped += String.fromCharCode(crep[2]);
  25060. continue;
  25061. }
  25062. else {
  25063. shaped += String.fromCharCode(crep[1]);
  25064. }
  25065. }
  25066. else {
  25067. shaped += String.fromCharCode(current);
  25068. }
  25069. }
  25070. return shaped;
  25071. }
  25072. convertArabicBack(apfb) {
  25073. var toReturn = '', selectedChar;
  25074. var i;
  25075. for (i = 0; i < apfb.length; ++i) {
  25076. selectedChar = apfb.charCodeAt(i);
  25077. toReturn += this.getOriginalCharsFromCode(selectedChar);
  25078. }
  25079. return toReturn;
  25080. }
  25081. }
  25082. ArabicReshaper.charsMap = [[0x0621, 0xFE80, null, null, null],
  25083. [0x0622, 0xFE81, null, null, 0xFE82],
  25084. [0x0623, 0xFE83, null, null, 0xFE84],
  25085. [0x0624, 0xFE85, null, null, 0xFE86],
  25086. [0x0625, 0xFE87, null, null, 0xFE88],
  25087. [0x0626, 0xFE89, 0xFE8B, 0xFE8C, 0xFE8A],
  25088. [0x0627, 0xFE8D, null, null, 0xFE8E],
  25089. [0x0628, 0xFE8F, 0xFE91, 0xFE92, 0xFE90],
  25090. [0x0629, 0xFE93, null, null, 0xFE94],
  25091. [0x062A, 0xFE95, 0xFE97, 0xFE98, 0xFE96],
  25092. [0x062B, 0xFE99, 0xFE9B, 0xFE9C, 0xFE9A],
  25093. [0x062C, 0xFE9D, 0xFE9F, 0xFEA0, 0xFE9E],
  25094. [0x062D, 0xFEA1, 0xFEA3, 0xFEA4, 0xFEA2],
  25095. [0x062E, 0xFEA5, 0xFEA7, 0xFEA8, 0xFEA6],
  25096. [0x062F, 0xFEA9, null, null, 0xFEAA],
  25097. [0x0630, 0xFEAB, null, null, 0xFEAC],
  25098. [0x0631, 0xFEAD, null, null, 0xFEAE],
  25099. [0x0632, 0xFEAF, null, null, 0xFEB0],
  25100. [0x0633, 0xFEB1, 0xFEB3, 0xFEB4, 0xFEB2],
  25101. [0x0634, 0xFEB5, 0xFEB7, 0xFEB8, 0xFEB6],
  25102. [0x0635, 0xFEB9, 0xFEBB, 0xFEBC, 0xFEBA],
  25103. [0x0636, 0xFEBD, 0xFEBF, 0xFEC0, 0xFEBE],
  25104. [0x0637, 0xFEC1, 0xFEC3, 0xFEC4, 0xFEC2],
  25105. [0x0638, 0xFEC5, 0xFEC7, 0xFEC8, 0xFEC6],
  25106. [0x0639, 0xFEC9, 0xFECB, 0xFECC, 0xFECA],
  25107. [0x063A, 0xFECD, 0xFECF, 0xFED0, 0xFECE],
  25108. [0x0640, 0x0640, 0x0640, 0x0640, 0x0640],
  25109. [0x0641, 0xFED1, 0xFED3, 0xFED4, 0xFED2],
  25110. [0x0642, 0xFED5, 0xFED7, 0xFED8, 0xFED6],
  25111. [0x0643, 0xFED9, 0xFEDB, 0xFEDC, 0xFEDA],
  25112. [0x0644, 0xFEDD, 0xFEDF, 0xFEE0, 0xFEDE],
  25113. [0x0645, 0xFEE1, 0xFEE3, 0xFEE4, 0xFEE2],
  25114. [0x0646, 0xFEE5, 0xFEE7, 0xFEE8, 0xFEE6],
  25115. [0x0647, 0xFEE9, 0xFEEB, 0xFEEC, 0xFEEA],
  25116. [0x0648, 0xFEED, null, null, 0xFEEE],
  25117. [0x0649, 0xFEEF, null, null, 0xFEF0],
  25118. [0x064A, 0xFEF1, 0xFEF3, 0xFEF4, 0xFEF2],
  25119. [0x067E, 0xFB56, 0xFB58, 0xFB59, 0xFB57],
  25120. [0x06CC, 0xFBFC, 0xFBFE, 0xFBFF, 0xFBFD],
  25121. [0x0686, 0xFB7A, 0xFB7C, 0xFB7D, 0xFB7B],
  25122. [0x06A9, 0xFB8E, 0xFB90, 0xFB91, 0xFB8F],
  25123. [0x06AF, 0xFB92, 0xFB94, 0xFB95, 0xFB93],
  25124. [0x0698, 0xFB8A, null, null, 0xFB8B]];
  25125. ArabicReshaper.combCharsMap = [[[0x0644, 0x0622], 0xFEF5, null, null, 0xFEF6],
  25126. [[0x0644, 0x0623], 0xFEF7, null, null, 0xFEF8],
  25127. [[0x0644, 0x0625], 0xFEF9, null, null, 0xFEFA],
  25128. [[0x0644, 0x0627], 0xFEFB, null, null, 0xFEFC]];
  25129. ArabicReshaper.transChars = [0x0610,
  25130. 0x0612,
  25131. 0x0613,
  25132. 0x0614,
  25133. 0x0615,
  25134. 0x064B,
  25135. 0x064C,
  25136. 0x064D,
  25137. 0x064E,
  25138. 0x064F,
  25139. 0x0650,
  25140. 0x0651,
  25141. 0x0652,
  25142. 0x0653,
  25143. 0x0654,
  25144. 0x0655,
  25145. 0x0656,
  25146. 0x0657,
  25147. 0x0658,
  25148. 0x0670,
  25149. 0x06D6,
  25150. 0x06D7,
  25151. 0x06D8,
  25152. 0x06D9,
  25153. 0x06DA,
  25154. 0x06DB,
  25155. 0x06DC,
  25156. 0x06DF,
  25157. 0x06E0,
  25158. 0x06E1,
  25159. 0x06E2,
  25160. 0x06E3,
  25161. 0x06E4,
  25162. 0x06E7,
  25163. 0x06E8,
  25164. 0x06EA,
  25165. 0x06EB,
  25166. 0x06EC,
  25167. 0x06ED];
  25168. class MatirxArray {
  25169. static ArrayMul(a, b, o) {
  25170. if (!a) {
  25171. MatirxArray.copyArray(b, o);
  25172. return;
  25173. }
  25174. if (!b) {
  25175. MatirxArray.copyArray(a, o);
  25176. return;
  25177. }
  25178. var ai0, ai1, ai2, ai3;
  25179. for (var i = 0; i < 4; i++) {
  25180. ai0 = a[i];
  25181. ai1 = a[i + 4];
  25182. ai2 = a[i + 8];
  25183. ai3 = a[i + 12];
  25184. o[i] = ai0 * b[0] + ai1 * b[1] + ai2 * b[2] + ai3 * b[3];
  25185. o[i + 4] = ai0 * b[4] + ai1 * b[5] + ai2 * b[6] + ai3 * b[7];
  25186. o[i + 8] = ai0 * b[8] + ai1 * b[9] + ai2 * b[10] + ai3 * b[11];
  25187. o[i + 12] = ai0 * b[12] + ai1 * b[13] + ai2 * b[14] + ai3 * b[15];
  25188. }
  25189. }
  25190. static copyArray(f, t) {
  25191. if (!f)
  25192. return;
  25193. if (!t)
  25194. return;
  25195. for (var i = 0; i < f.length; i++) {
  25196. t[i] = f[i];
  25197. }
  25198. }
  25199. }
  25200. exports.AlphaCmd = AlphaCmd;
  25201. exports.Animation = Animation;
  25202. exports.AnimationBase = AnimationBase;
  25203. exports.ArabicReshaper = ArabicReshaper;
  25204. exports.AtlasGrid = AtlasGrid;
  25205. exports.AtlasInfoManager = AtlasInfoManager;
  25206. exports.AudioSound = AudioSound;
  25207. exports.AudioSoundChannel = AudioSoundChannel;
  25208. exports.BasePoly = BasePoly;
  25209. exports.BaseShader = BaseShader;
  25210. exports.BaseTexture = BaseTexture;
  25211. exports.Bezier = Bezier;
  25212. exports.Bitmap = Bitmap;
  25213. exports.BitmapFont = BitmapFont;
  25214. exports.BlendMode = BlendMode;
  25215. exports.BlurFilter = BlurFilter;
  25216. exports.BlurFilterGLRender = BlurFilterGLRender;
  25217. exports.BlurFilterSetter = BlurFilterSetter;
  25218. exports.BoundsStyle = BoundsStyle;
  25219. exports.Browser = Browser;
  25220. exports.Buffer = Buffer;
  25221. exports.Buffer2D = Buffer2D;
  25222. exports.BufferState2D = BufferState2D;
  25223. exports.BufferStateBase = BufferStateBase;
  25224. exports.ButtonEffect = ButtonEffect;
  25225. exports.Byte = Byte;
  25226. exports.CONST3D2D = CONST3D2D;
  25227. exports.CacheManger = CacheManger;
  25228. exports.CacheStyle = CacheStyle;
  25229. exports.CallLater = CallLater;
  25230. exports.CharRenderInfo = CharRenderInfo;
  25231. exports.CharRender_Canvas = CharRender_Canvas;
  25232. exports.CharRender_Native = CharRender_Native;
  25233. exports.CharSubmitCache = CharSubmitCache;
  25234. exports.ClassUtils = ClassUtils;
  25235. exports.ClipRectCmd = ClipRectCmd;
  25236. exports.ColorFilter = ColorFilter;
  25237. exports.ColorFilterSetter = ColorFilterSetter;
  25238. exports.ColorUtils = ColorUtils;
  25239. exports.CommandEncoder = CommandEncoder;
  25240. exports.CommonScript = CommonScript;
  25241. exports.Component = Component;
  25242. exports.Config = Config;
  25243. exports.Const = Const;
  25244. exports.Context = Context;
  25245. exports.Dragging = Dragging;
  25246. exports.Draw9GridTexture = Draw9GridTexture;
  25247. exports.DrawCanvasCmd = DrawCanvasCmd;
  25248. exports.DrawCircleCmd = DrawCircleCmd;
  25249. exports.DrawCurvesCmd = DrawCurvesCmd;
  25250. exports.DrawImageCmd = DrawImageCmd;
  25251. exports.DrawLineCmd = DrawLineCmd;
  25252. exports.DrawLinesCmd = DrawLinesCmd;
  25253. exports.DrawParticleCmd = DrawParticleCmd;
  25254. exports.DrawPathCmd = DrawPathCmd;
  25255. exports.DrawPieCmd = DrawPieCmd;
  25256. exports.DrawPolyCmd = DrawPolyCmd;
  25257. exports.DrawRectCmd = DrawRectCmd;
  25258. exports.DrawStyle = DrawStyle;
  25259. exports.DrawTextureCmd = DrawTextureCmd;
  25260. exports.DrawTexturesCmd = DrawTexturesCmd;
  25261. exports.DrawTrianglesCmd = DrawTrianglesCmd;
  25262. exports.Earcut = Earcut;
  25263. exports.EarcutNode = EarcutNode;
  25264. exports.Ease = Ease;
  25265. exports.EffectAnimation = EffectAnimation;
  25266. exports.EffectBase = EffectBase;
  25267. exports.Event = Event;
  25268. exports.EventDispatcher = EventDispatcher;
  25269. exports.FadeIn = FadeIn;
  25270. exports.FadeOut = FadeOut;
  25271. exports.FillBorderTextCmd = FillBorderTextCmd;
  25272. exports.FillBorderWordsCmd = FillBorderWordsCmd;
  25273. exports.FillTextCmd = FillTextCmd;
  25274. exports.FillTextureCmd = FillTextureCmd;
  25275. exports.FillWordsCmd = FillWordsCmd;
  25276. exports.Filter = Filter;
  25277. exports.FilterSetterBase = FilterSetterBase;
  25278. exports.FontInfo = FontInfo;
  25279. exports.FrameAnimation = FrameAnimation;
  25280. exports.GlowFilter = GlowFilter;
  25281. exports.GlowFilterGLRender = GlowFilterGLRender;
  25282. exports.GlowFilterSetter = GlowFilterSetter;
  25283. exports.GrahamScan = GrahamScan;
  25284. exports.GraphicAnimation = GraphicAnimation;
  25285. exports.Graphics = Graphics;
  25286. exports.GraphicsBounds = GraphicsBounds;
  25287. exports.HTMLCanvas = HTMLCanvas;
  25288. exports.HTMLChar = HTMLChar;
  25289. exports.HTMLImage = HTMLImage;
  25290. exports.Handler = Handler;
  25291. exports.HitArea = HitArea;
  25292. exports.HttpRequest = HttpRequest;
  25293. exports.ICharRender = ICharRender;
  25294. exports.ILaya = ILaya;
  25295. exports.IStatRender = IStatRender;
  25296. exports.IndexBuffer2D = IndexBuffer2D;
  25297. exports.InlcudeFile = InlcudeFile;
  25298. exports.Input = Input;
  25299. exports.KeyBoardManager = KeyBoardManager;
  25300. exports.KeyLocation = KeyLocation;
  25301. exports.Keyboard = Keyboard;
  25302. exports.Laya = Laya;
  25303. exports.LayaGL = LayaGL;
  25304. exports.LayaGLQuickRunner = LayaGLQuickRunner;
  25305. exports.LayaGLRunner = LayaGLRunner;
  25306. exports.LayaGPU = LayaGPU;
  25307. exports.Loader = Loader;
  25308. exports.LoaderManager = LoaderManager;
  25309. exports.LocalStorage = LocalStorage;
  25310. exports.Log = Log;
  25311. exports.MathUtil = MathUtil;
  25312. exports.MatirxArray = MatirxArray;
  25313. exports.Matrix = Matrix;
  25314. exports.Mesh2D = Mesh2D;
  25315. exports.MeshParticle2D = MeshParticle2D;
  25316. exports.MeshQuadTexture = MeshQuadTexture;
  25317. exports.MeshTexture = MeshTexture;
  25318. exports.MeshVG = MeshVG;
  25319. exports.Mouse = Mouse;
  25320. exports.MouseManager = MouseManager;
  25321. exports.Node = Node;
  25322. exports.Path = Path;
  25323. exports.PerfData = PerfData;
  25324. exports.PerfHUD = PerfHUD;
  25325. exports.Point = Point;
  25326. exports.Pool = Pool;
  25327. exports.PoolCache = PoolCache;
  25328. exports.Prefab = Prefab;
  25329. exports.PrimitiveSV = PrimitiveSV;
  25330. exports.QuickTestTool = QuickTestTool;
  25331. exports.Rectangle = Rectangle;
  25332. exports.Render = Render;
  25333. exports.RenderInfo = RenderInfo;
  25334. exports.RenderSprite = RenderSprite;
  25335. exports.RenderState2D = RenderState2D;
  25336. exports.RenderTexture2D = RenderTexture2D;
  25337. exports.Resource = Resource;
  25338. exports.ResourceVersion = ResourceVersion;
  25339. exports.RestoreCmd = RestoreCmd;
  25340. exports.RotateCmd = RotateCmd;
  25341. exports.RunDriver = RunDriver;
  25342. exports.SaveBase = SaveBase;
  25343. exports.SaveClipRect = SaveClipRect;
  25344. exports.SaveCmd = SaveCmd;
  25345. exports.SaveMark = SaveMark;
  25346. exports.SaveTransform = SaveTransform;
  25347. exports.SaveTranslate = SaveTranslate;
  25348. exports.ScaleCmd = ScaleCmd;
  25349. exports.Scene = Scene;
  25350. exports.SceneLoader = SceneLoader;
  25351. exports.SceneUtils = SceneUtils;
  25352. exports.Script = Script;
  25353. exports.Shader = Shader;
  25354. exports.Shader2D = Shader2D;
  25355. exports.Shader2X = Shader2X;
  25356. exports.ShaderCompile = ShaderCompile;
  25357. exports.ShaderDefines2D = ShaderDefines2D;
  25358. exports.ShaderDefinesBase = ShaderDefinesBase;
  25359. exports.ShaderNode = ShaderNode;
  25360. exports.ShaderValue = ShaderValue;
  25361. exports.SkinMeshBuffer = SkinMeshBuffer;
  25362. exports.SkinSV = SkinSV;
  25363. exports.Socket = Socket;
  25364. exports.Sound = Sound;
  25365. exports.SoundChannel = SoundChannel;
  25366. exports.SoundManager = SoundManager;
  25367. exports.SoundNode = SoundNode;
  25368. exports.Sprite = Sprite;
  25369. exports.SpriteConst = SpriteConst;
  25370. exports.SpriteStyle = SpriteStyle;
  25371. exports.Stage = Stage;
  25372. exports.Stat = Stat;
  25373. exports.StatUI = StatUI;
  25374. exports.StringKey = StringKey;
  25375. exports.StrokeTextCmd = StrokeTextCmd;
  25376. exports.Submit = Submit;
  25377. exports.SubmitBase = SubmitBase;
  25378. exports.SubmitCMD = SubmitCMD;
  25379. exports.SubmitCanvas = SubmitCanvas;
  25380. exports.SubmitKey = SubmitKey;
  25381. exports.SubmitTarget = SubmitTarget;
  25382. exports.SubmitTexture = SubmitTexture;
  25383. exports.System = System;
  25384. exports.TTFLoader = TTFLoader;
  25385. exports.Text = Text;
  25386. exports.TextAtlas = TextAtlas;
  25387. exports.TextRender = TextRender;
  25388. exports.TextStyle = TextStyle;
  25389. exports.TextTexture = TextTexture;
  25390. exports.Texture = Texture;
  25391. exports.Texture2D = Texture2D;
  25392. exports.TextureSV = TextureSV;
  25393. exports.TimeLine = TimeLine;
  25394. exports.Timer = Timer;
  25395. exports.TouchManager = TouchManager;
  25396. exports.TransformCmd = TransformCmd;
  25397. exports.TranslateCmd = TranslateCmd;
  25398. exports.Tween = Tween;
  25399. exports.URL = URL;
  25400. exports.Utils = Utils;
  25401. exports.Value2D = Value2D;
  25402. exports.VectorGraphManager = VectorGraphManager;
  25403. exports.VertexArrayObject = VertexArrayObject;
  25404. exports.VertexBuffer2D = VertexBuffer2D;
  25405. exports.WeakObject = WeakObject;
  25406. exports.WebAudioSound = WebAudioSound;
  25407. exports.WebAudioSoundChannel = WebAudioSoundChannel;
  25408. exports.WebGL = WebGL;
  25409. exports.WebGLCacheAsNormalCanvas = WebGLCacheAsNormalCanvas;
  25410. exports.WebGLContext = WebGLContext;
  25411. exports.WebGLRTMgr = WebGLRTMgr;
  25412. exports.WordText = WordText;
  25413. exports.WorkerLoader = WorkerLoader;
  25414. exports.__init = __init;
  25415. exports._static = _static;
  25416. exports.alertGlobalError = alertGlobalError;
  25417. exports.enableDebugPanel = enableDebugPanel;
  25418. exports.init = init;
  25419. exports.isWXOpenDataContext = isWXOpenDataContext;
  25420. exports.isWXPosMsg = isWXPosMsg;
  25421. exports.version = version;
  25422. exports.static=_static;
  25423. return exports;
  25424. }({}));