微软出品简洁色块型PPT

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

BuildingaHighPerformance3DGamesforWindowsPhoneAdamSchaefferMicrosoftCorporationSESSIONCODE:WPH308(IntelliSense)SimilarenoughtoCthatlearningandportingareeasyBlazinglyfastcompilesC#.NETonWindowsUsuallywithinafewpercentofnativeperformanceAwesomegenerationalgarbagecollectionPerformanceshootout:RaymondChenvs.RicoMariani!ARMv7CPUMoreforgivingtowardjittedcodeARMjitterismorematurethanPPCWaysToCallCodeInstancemethodInterfaceDelegate/eventReflectionVirtualmethodChooseYourOwnAddressC++allowsindependentchoiceof.NETtypesdictatetheirallocationandusagesemanticsDatatypeThememoryinwhichatypelives(placementnew)Howatypeinstanceisreferenced(T,T*,T&,constT&)Valuetypesint,bool,struct,Vector3Referencetypesclass,array,string,delegate,boxedvaluetypesAPopularMythOft-repeatedwisdomValuetypesliveonthestackReferencetypesliveontheheapValuetypeslivewherevertheyaredeclaredReferencetypeshavetwopiecesMemoryallocatedfromtheheapApointertothisheapmemoryThatissubtlyincorrectBydefault,preferclassoverstructureUsestructforthingsthatareclassvs.structSmall(=16bytes)ShortlivedPasslargestructuresbyreferenceMatrixa,b,c;c=Matrix.Multiply(a,b);//copies192bytes!Matrix.Multiply(refa,refb,outc);MemoryManagementC++.NETAllocateInitiallyfast,becomingslowerasfragmentationincreasesVeryfast,apartfromperiodicgarbagecollectionsFreeFastInstantaneousFragmentationIncreasesovertimeNoneCachecoherencyRequirescustomallocatorsThingsallocatedcloseintimearealsocloseinphysicallocationGarbagecollectionisnotoptionalCan’thavetypesafetywithoutautomaticmemorymanagementMarkandSweepTriggeredpermegabyteofallocation1Startswithrootreferences(stackvariables,statics)2Recursivelyfollowsallreferencestoseewhatotherobjectscanbereached3Anythingwedidn’treachmustbegarbage4Compactstheheap,slidingliveobjectsdowntofillholes5FrameworksdesignedforperformanceFrameworksdesignedforperformanceTwoWaysToKeepGCHappyMakeitrunLessOftenIfyouneverallocate,GCwillneverrunMakeitFinishQuicklyCollectiontimeisproportionaltohowmanyobjectreferencesmustbetraversedUseobjectpoolsSimpleheap=fastcollectionUsevaluetypesandintegerhandlesGC.CollectExplicitlyforcesagarbagecollectionUsewiselytogiveyourselfmoreheadroomAfterloadingDuringpausesingameplayDon’tcalleveryframe!AvoidingAllocationBewareofboxingstringvs.StringBuilderUseWeakReferencetotrackGCfrequency’10talk:“DevelopmentandDebuggingToolsforWindowsPhone7Series”Use.NETReflectortopeekbehindthecurtain•0-3directionallights•Blinn-Phongshading•Optionaltexture•Optionalfog•OptionalvertexcolorBasicEffectVertexCostPixelCostNolighting51Onevertexlight401Threevertexlights601Threepixellights1850+Texture+1+2+Fog+4+2DualTextureEffectDualTextureEffect•Forlightmaps,detailtextures,decals•Blendstwotextures•Separatetexturecoordinates•Modulate2Xcombinemode(A*B*2)•GoodvisualsatlowpixelcostVertexCostPixelCostTwoTextures76+Fog+4+2AlphaTestEffect•Forbillboardsandimposters•Addsalphatestoperations(pixelkill)•Standardblendingisfreewithalleffects•Onlyneedalphatestifyouwanttodisabledepth/stencilwritesAlphaTestEffectVertexCostPixelCost,=,=,66==,!=610+Fog+4+2SkinnedEffectSkinnedEffect•Foranimatedmodelsandinstancing•GamecodeanimatesbonesonCPU•VertexskinningperformedbyGPU•Upto72bones•One,two,orfourweightspervertexVertexCostPixelCostOnevertexlight554Threevertexlights754Threepixellights3351+Twobones+7+0+Fourbones+13+0+Fog+0+2EnvironmentMapEffectEnvironmentMapEffect•Oooh,shiny!•Diffusetexture+cubeenvironmentmap•Cheapwaytofakemanycomplexlights•Fresneltermsimulatesbehaviorwhenlightreachesasurfaceandsomereflects,somepenetratesVertexCostPixelCostOnelight326Threelights366+Fresnel+7+0+Specular+0+2+Fog+0+2ABalancingActFramerateNumberofPixelsPixelCostBalancingFramerateFramerate•30hzrefreshrate•Nopointupdatingfasterthanthedisplay!Game.TargetElapsedTime=TimeSpan.FromSeconds(1f/30);ABalancingActPixelCost•Prefercheapereffects•MinimizeoverdrawManyknownalgorithms:Distance,frustum,BSP,sortfr

1 / 33
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功