/
Declarative Processing for Computer Games Walker White Declarative Processing for Computer Games Walker White

Declarative Processing for Computer Games Walker White - PDF document

karlyn-bohler
karlyn-bohler . @karlyn-bohler
Follow
399 views
Uploaded On 2015-05-25

Declarative Processing for Computer Games Walker White - PPT Presentation

cornelledu Benjamin Sowell Cornell University sowellcscornelledu Johannes Gehrke Cornell University johannescscornelledu Alan Demers Cornell University ademerscscornelledu Abstract Most game developers think of databases as nothing more than a persis ID: 74302

cornelledu Benjamin Sowell Cornell University

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "Declarative Processing for Computer Game..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Toprovidegameswiththeseperformancebenets,weneedtoiden-tifyandseparatejoinsfromarbitraryiterationinthegamelogic.Ingeneral,thisisaverydifcultproblem.Abettersolutionistoidentifydesignpatternsthatareadaptabletoouroptimizationsandtoprovidetoolsforprocessingthesepatterns.Inthissectionwepresentabasicdesignpatternthatallowsforextensivedeclarativeoptimizations.Inaddition,weillustratethispatternwithseveralexamplesshowingitswiderangeofapplicability.2.1TheState-EffectDesignPatternWecallourdesignpatternthestate-effectpattern.Inpractice,thispatternisappliedtopartorallofthegamesimulationloop(i.e.thepartofthegamethatprocessesobjectbehaviorandupdatesthegamestate).Inthispattern,weseparatetheattributesofthegameobjectsintotwodisjointtypes:statesandeffects.Naively,statesarevaluesthatchangeonlyattheendofthesimulationtimestep,butwhichremainconstantduringthemaincomputationalphase.Effects,ontheotherhand,areephemeralvaluesthatcanchangewithinthesimulationloopastheobjectinteractswithotherobjectsinthegame.Inadditiontoseparatingstatesandeffects,weputrestrictionsonhowthesetwotypesofobjectattributescaninteractwithoneanother.Beforeweoutlinethepatternindetail,werstconsideranexamplethatisalreadyfamiliartomostgamedevelopers:aparticlesystem.Initssimplestform,theattributesofanobjectofaparticlesystemaremass,volume,position,velocityand(possibly)acceleration.Inaddition,duringasinglesimulationtimestep,eachparticlehasaforceattributewhichrepresentstheinteractionswithalloftheotherobjectsintheparticlesystem.Thesimulationloopcomputesthisforceattribute,andusesittoupdatetheotherparticleattributesinthefollowingway:(1)Itsumsupalloftheforcesactinguponeachparticle.(2)Fromtheseforces,itcomputesthenewaccelerationand/orvelocityforeachparticle.(3)Ittentativelymovestheparticleseachtotheirnewpositionaccordingtotheaccelerationand/orvelocity.(4)Finally,itsearchesforanycollisionsthatoccurredduringtheprocess,andbacksthemoutasnecessary.Ignoringfornowthecollisiondetectionandresolutionphaseinstep(4),wecaneasilyseparatethisprocessintostatesandeffects.Theforceattributeisaneffectthatiscomputedfrominteractionswithotherobjects.Itcanbecomputedusingajoin,aswejustloopoveralltheothergameobjectswithafor-eachandsumtheresultstogether.Theotherattributes—position,velocity,acceleration—areonlyupdatedattheendoftheloopandthereforemaybeclas-siedasstate.Furthermore,statevaluesareupdatedusingonlyasimplemathematicalcalculationfromtheforceattributeandtheexistingstatevalues;nofurtheriterationisrequired.Apowerfulfeatureofthisdesignisthat,becausethestateisnotup-dateduntiltheendofthesimulationloop,theforcecalculationscanallbeisolatedfromoneanother.Wecanevaluatethegameobjectsinanyorder,oreveninparallel,andstillgetthesameanswer.ThisfeaturehasbeenheavilyutilizedbygameengineerstoparallelizephysicscomputationsonmodernGPUs[Nguyen2007].Theabil-itytodoorder-independentprocessingisthecrucialpropertythatallowsustooptimizethiscalculationwithdatabasetechniques.Giventheparticlesystemasourmotivation,wenowoutlinethestate-effectpatterninmoredetail.Itconsistsofthefollowingparts:Separationofobjectattributesintostatesandeffects.Stateattributesremainunchangedforthemajorityofasim-ulationtimestep,onlychangingattheend.Effectattributes,ontheotherhand,supportintermediatecomputation.Theycanchangewithinthesimulationloop,butare“reset”atthebeginningofeverytimestep.Inthosecaseswherewewantanattributetobebothastateandaneffect,wemakeaseparateattributeforeachrole.Intheparticlesystemexample,forceisaneffectwhileallotherattributesarestate.Rulesforcombiningeffectswithinasingletimestep.Intuitively,effectsrepresentactionsthatagameobjectcanperformeitheronitselforonotherobjects.Theseeffectscanincludeactionsfromintelligentagents,suchastheresultofamagicspell,oractionsfrominanimateobjects,suchastheforceexertedbyoneparticleonanother.Asallactionsinasingletimestepareappliedsimultaneously,weneedorder-independentrulesforcombiningtheseeffectstoproduceasingleneteffect.Inourparticlesystemexample,summationistheruleforcombiningindividualforceeffects.Thisruleisindependentofordersincesummationisassociativeandcommutative.(QueryPhase)Specicationofobjectinteractions.Foreachgameobject,weneedinstructionsspecifyingwhateffectsiteithergeneratesorincurs.Ifweweretouseascriptinglanguagetoimplementourpattern,theseinstruc-tionswouldbescriptsattachedtotheindividualgameobjects.Theseinstructionshaveonemajorrestriction;thequeryphasemaynothaveanyformofiterationotherthanajoin(e.g.afor-eachloop).Inourparticlesystemexample,thequeryphaseconsistsofthemathematicalformulaecomputingtheforcebetweenpairsofparticles.(Post-processingPhase)Specicationforupdatingstate.Attheendofthesimulationloop,weneedinstructionsforhowtocomputethenewstatefromtheeffectsthatwehave.Forefciency,wewouldpreferthattheinstructionsbesimplecalculationsdoneinstraight-linecode.However,tomakeiteasiertointegratethispatternintotherestofthegame,weplacenorestrictionsonthispartofthepattern;itmayevenincludeinstructionsthatcannotbecomputeddeclaratively.Inourparticlesystemexample,steps(2)and(3)areexamplesofsimplepost-processingwhichupdatesthestatefromtheeffect.Furthermore,sincetherearenorestrictionsonwhatwedointhepost-processingphase,wecanincludestep(4),whichmayinvolveunsafeiteration.Thenames“queryphase”and“post-processingphase”arechosentoreectthewaysinwhichweprocessthesesteps.Supposethateachofourgameobjectswerearowinadatabasetable.Becauseofourrestrictionsonthequeryphase,wecouldprocessitasasingledatabasequerythatreturnsanewtableofeffectsoneachoftheseobjects.Thepost-processingphasethenusesastandardprogram-mingmodeltoupdatetheseobjectsusingthevaluesinthiseffecttable.AsweshowinSection4,thebenetsofusingtraditionaldatabasetechniquestospeedupthequeryphasecanbeenormous.Theprimarydifcultywiththisdesignpatternisthatwehavetobecarefulwithwhatweputinthepost-processingstep;itcaneasilybecomea“catch-all”stepforpartsthatarehardtoseparate.Thereislittleadvantageforourpatterninthepost-processingphase,asitishandlednormallywithoutdeclarativeoptimizations.Hence,ifweputtoomuchinthisphase,thecostofthisphasecandominatetheoptimizationsdescribedinSection4.WediscussthisissueinmoredetailinSection5.2. classUnit{state:numberplayer=0;numbertype=0;numberx=0;numbery=0;numberhealth=0;Unittarget=null;effects:numbervx:avg;numbervy:avg;numberdamage:sum;numberhealing:max;Unitacquired:priority;update:x=x+vx;y=y+vy;health=health-damage;target=(acquired!=null?acquired:target);}Figure2:SampleDatatypeDeclarationtionstakeanexpressionhEXPiandasetofobjects.Theexpres-sionisevaluatedoneachobjectintheset,andthefunctionreturnstheonewiththeminimum(ormaximum)value.Forexample,wecoulduseargmintochosetheenemyunitthatisclosesttoourcharacter;wesimplyprovidetheexpressioncomputingdistancetothefunctionargmin.Inthosecaseswherethereismorethanoneminimum(ormaximum),thesefunctionsusethebuilt-inpriorityvaluetobreakties.Inadditiontoattributes,thedatalealsospeciesupdaterules.Theupdaterulesareexpressionsdenedintermsoftheeffectandstateelds.Theyareusedtodenethenewvalueofeachstateeldattheendofthepost-processingstage.Forexample,inFig-ure2,theupdaterulesusethevelocityeffectstoadjustthepositionstate.ThereforeSGLcanhandleverysimplepost-processingin-structions,likesteps(2)and(3)inourparticlesystemexample.Formorecomplicatedpost-processingoperations,werelyontheintegrationbetweenSGLandthegameengine.ThegameengineinvokesSGLbycallingafunctionwhichprocessesasinglestepofthequeryphase,followedbyanapplicationoftheupdaterules.Thegameengineisfreetodowhateveroperationsitwantstothegameobjectsbeforeinvokingthescriptagain.Thuswecansafelyignoremorecomplexpost-processingexamplessuchasstep(4)inourparticlesystemexample.Thescriptlesarestructuredtolooklikeanimperativeprogram-minglanguage,eventhoughtheyareprocesseddeclaratively.Thisisintendedtomakethescriptinglanguagemoreaccessibletode-signerswhohavenoexperiencewithdeclarativelanguages.Eachscriptleisassociatedwithadatatype,andalloftheeldsofthatdatatypemaybeaccessedinthatscriptwithoutadot.Inaddition,eldsofotherobjectsareaccessedusingthetraditional“dotselec-tion”foundinmostobject-orientedlanguages.Forexample,inascriptassociatedwithaunittype,“x”isthexpositionoftheunitexecutingthescript,while“target.x”isthexpositionofthecurrentcombattargetofthescriptexecutor.Thescriptinglanguagehasmanyfeaturescommontoscriptinglan-guages,suchasif-elseconditionals.Furthermore,ithasex-pressionsformanipulatingnumbers,objects,andsetsofobjects.Forbrevity,wefocusonthemostimportantpartsofthescript.Theprimarypurposeofthescriptistoassignvaluestotheeffectelds.Ascriptmayassignavaluetoaneffecteldoftheobjectexecutingthescript,ortoaneffecteldofanotherobject.Inordertoprocessthescriptasefcientlyaspossible,thereisnoguaranteeontheorderinwhichthevaluesareassignedtotheeffectelds;let(numberdist=(x-target.x)*(x-target.x)+(y-target.y)*(y-target.y))in{if(distATTACK_RANGE){//Ifinrange,attack.target.damageDMG_AMOUNT;}else{//Elsemovecloser(useunitvelocity)vx(target.x-x)/dist;vx(target.y-y)/dist;}}Figure3:AssigningEffectValuesifmorethanonevalueisassignedtoaneffectvalue,thenthesevaluesarecombinedusingtherulesspeciedinthedatale.Addi-tionally,inordertopreventhazardoussideeffectssuchasreadingeffectsassignedoutoforder,effecteldsmayneverberead—theyarewrite-only.Inessence,oureffecteldsworkliketheaggregatevariablesfoundinSawzall,Google'shighlyparallelizabledatapro-cessinglanguage[Pikeetal.2005].Indeed,ournotationforwritingtoaneffecteld,“”,isthesameasSawzall's.SGLprovideslocalvariablestostoreandaccesstheresultsofinter-mediatecomputation.However,asinafunctionallanguage,thesevariablesmayneverbereassignedaftertheyaredened.Aslongasthereisnoiterationinthescript,thisdoesnotactuallyplaceanyrestrictionsonthedesigner.Furthermore,sincewehandleitera-tionspecially,webelievethisisanacceptabletrade-offinlanguageexpressivenesstomakeprocessingsimpler.TointroduceanintermediatevariableinaSGL,weusethesyntaxlethTYPEihidentiferi=hEXPiinfhBLOCKigThescopeofthisvariableisthecodeblocksurroundedbythebraces.Figure3showstheuseofaletdeclarationtorepresentaunitchoosingbetweentwoactions,dependingonthedistancebetweenitanditscombattarget.SGLsupportsmultiplevariableassignmentsinasingleletstatement;theymustallbepartofacomma-separatedlist.Inadditiontoletstatements,SGLsupportsalimitedformofiter-ation.Again,inordertoimproveourabilitytooptimizetheexecu-tionofascript,wewishtoavoidvariablesthatcanbebothreadandwrittenarbitrarily.Therefore,ourdesignofthisiterationloopitselffollowsthestate-effectpattern.Wecallouriterationaccum-loops,andtheyhavethesyntaxaccumhTYPEihidentifieri1withhCOMBINATORioverhTYPEihidentifieri2fromhEXPifhBLOCKi1ginfhBLOCKi2gNaively,thisloopusestherstcodeblock,hBLOCKi1,toiterateovertheelementsinthesethEXPi,andthenmakestheresultsofthatiterationavailabletothesecondcodeblock,hBLOCKi2.Withintherstcodeblock,thevariablehidentieri1istreatedasaneffecteld.Wemakenoguaranteesontheorderinwhichtheaccumu-lationloopisprocessed;theelementsinhEXPicanbeprocessedinanyorder,oreveninparallel.Therefore,withinhBLOCKi1,thevariablehidentieri1mayneverberead,andvaluesareassignedtoitusingthesame“”operatoraseffectelds.AtthecompletionofhBLOCKi1,theaccum-loopcombinesallofthevaluesassignedtohidentieri1usingthecombinationfunc-tionhCOMBINATORi.Thiscombinatorfunctioncanbeanyofthefunctionsweusedforeffectelds.Oncethesevaluesarecom-bined,theymaybereadfromthevariableinthesecondcodeblock,hBLOCKi2.Aswithaletstatement,thevariablehidentieri1mayneverbereassignedinhBLOCKi2;itisread-only. Figure5:ComparisonofNaiveProcessingversusIndexing Figure6:ComparisonofAggregateIndexingversusPruningbebetterjusttoprunethesearchspaceanditerateovertheprunedobjectsnormally.Thissolutioniscommonlyusedingames,anditoftenyieldsexcellentresults.Theproblemisthatthechoicebetweenaggregateindexingandsim-plepruningdependsonthecurrentstateofthegame.Forexample,consideragameinwhichwewanttodistributehealersformax-imumeffectiveness.Asimplealgorithmassignstoeachhealera“healingpriority.”Ateachtime-step,eachhealersearchesitsvisiblerangeforwoundedallieswhosehealthisbelowthisprior-ity.Withuniformlydistributedpriorityvalues,thisalgorithmdriveshealerstocongregateinareaswiththemostwounded.Obviously,iftherearefewwoundedunits,wecanprocessthisbehaviorveryefcientlybyjustpruningoutthehealthyallies.However,inapitchedbattlewithlargenumbersofwounded,weneedadifferenttechnique(likeaggregateindexing)toavoidthen2problem.Figure6showstheresultsofsimulatingthehealerbehaviorde-scribedaboveoverseveralhundredtimesteps.Thissimulationusesthesameprototypeasthepreviousaggregateindexsimula-tion[Whiteetal.2007],butwehaveisolatedtheperformancetothehealerbehavioronly.Thegraphcomparesthecostofbuildingandmaintaininganaggregateindextothatofsimplepruning.Thesimulationbeginsattheendofmajorbattle.Allalliedunitsarewounded,andsopruningisnotveryeffective.Overtime,thewoundedalliesaregraduallyhealeduntileventuallynomorewoundedremain.Asthenumberofwoundeddecreases,thecostofpruningdecreases,overtakingthecostoftheaggregateindexandeventuallyoutperformingitbyanotherorderofmagnitude.Ideally,wewouldliketokeepstatisticsthatenableustopredictwhichofpruningoraggregateindexingwillbemoreefcientonthecurrentgamestate,sowecanswitchbetweenthesequeryplansasnecessary.Thistechniqueiscalleddynamicqueryoptimization.Therehasbeensubstantialresearchondynamicqueryoptimization,particularlyonstreamingdata[Zhuetal.2004].Inasimulationenvironment,wecantheoreticallyachievetheperformanceoftheoptimalqueryplanateachtimestepwithaconstant(multiplicative)overhead.Inpracticewecanoftendomuchbetterthanthis.4.3OtherOptimizationsWhileourearlyworkonSGLhasfocusedonindexoptimization,thereareotherotherknownoptimizationtechniquesthatshouldap-plytothestate-effectpattern.Twothatareofparticularinterestforgamesarepipeliningandparallelization.WhilewehavenotappliedthesetechniquesspecicallytoSGL,therehasbeensomerecentworkonadaptingthemtoin-memorysystems.Pipeliningindatabaseprocessingworksmuchthesamewaythatitdoesincomputergraphics.Adatabasequeryplanconsistsofanumberofsimpleoperatorsconnectedtogetherinagraph.Withpipelinedevaluation,ratherthanmaterializingtheentireoutputre-lationofeachoperatorandstoringitinmemory,weinsteadgen-erateoutputvaluesincrementally,“ondemand.”Thiscangreatlyreducetheamountofmemoryrequiredforqueryprocessing:in-steadofallocatingmemoryforallintermediateresults,weprovideonlysmallinputandoutputbuffersforeachoperator.Largemem-oryblocksarerequiredonlyforaggregateindicesandforcertain“blocking”operators(suchassorting).Thisisparticularlyusefulforeffectelds,whichexistonlyduringthequeryphaseandupdaterules,andthusneedtobematerializedonlyintheinputandoutputbuffersofthepipeline.Gamedesignerssometimesdevelopcustomstreamingalgorithmssuchaspathnding[O'BrienandStout2007;Dunki2008]orGPUphysicssimulations[Nguyen2007].Inourapproach,pipeliningcomesforfreewhenwecompilethequeryphaseintoadeclara-tiveformat.Thusthegamedevelopercanfocusondesigningthebehaviorwithouthavingtoconstructcustompipelines.Anotherclassofoptimizationsrelevanttogamesisparallelization.Becausedatabasequerieshavenosideeffects(theytakestreamsofdataasinputandproducenewstreamsofdataasoutput)theyareembarrassinglyparallel[Dewittetal.1990;Stonebrakeretal.1988].Indeed,therehasevenbeenrecentworkonprocessingdatabasequerieswithGPUs[Govindarajuetal.2004].InthecaseofSGL,itisobvioushowtoparallelizeourqueryphase.Aseffectvariablescanneverberead,wecanisolatetheobjectsinthequeryphasefromoneanotherandprocessthemseparately.Wecanalsoparallelizeanyaccum-loopforexactlythesamereason.5GameDesignIssuesWhilethestate-effectpatternprovidesseveralperformanceadvan-tages,itisunusualanddoesrequirethatthegamedesignerstructurethegamelogicappropriately.Whileourformalizationofthestate-effectpatternisstillverynew,wehavealreadyidentiedtwomajordesignchallengesfromourinitialprototypes.5.1DesigningEffectsThemostobviouschallengedisthedesignofeffects.Veryoften,gamesupdatethestateofanobjectinthemiddleofthesimulationloop.Inordertotakeadvantageofthestate-effectpattern,thegamedevelopermustdesigneffectsthatappropriatelydelaytheupdateuntiltheendofthesimulationloop.Fortunately,gamedesignersalreadydoworkwitheffects.TheyareparticularlycommoninRPGs;thesegameshaveparalyzation effects,poisoneffects,performanceenhancingeffects,andsoon.Designingasingleeffectisusuallystraightforward.Thegamede-signerintroducesaeldfortheeffect,andspeciesrulesforhan-dlingthosecaseswhentheeffectisproducedmorethanonceinasingletimestep.Whilethismayresultinalargenumberofelds,thepipeliningprocessmentionedinSection4.3canminimizetheamountofmemorynecessarytoprocessthem.Agreaterchallengeismanagingtheinterplaybetweendifferentef-fects.Forgamebalancepurposeswemaynotwantcertaineffectstostackwithoneanother.Forexample,wemaywantacharactertoreceiveastrengthenhancementeffectoraspeedenhancementeffect,butnotboth.Onewaytoimplementthiswouldbetomodelstrengthandspeedenhancementsasseparateeffectelds,butwriteupdaterulessothatonlyoneofthemisusedatatime.However,thisbecomesunwieldyasweintroducemoreincompatibleeffects.Analternatesolutionistouseanobjecttorepresentaperformanceenhancementeffect.Then,inordertochoosethesingleeffectthattakeseffect,weuseapriorityfunction,—suchasargminorargmax—tochooseamongthem.Forexample,inmodel-ingperformanceenhancement,wemaywantanobjectwiththreeelds:theenhancementtype,theenhancementstrength,andtherankofthatenhancement,whereenhancementsofhigherrankaregivehigherpriorityoverthoseoflowerrank.Whenweassignanenhancementtoacharacterviaaneffecteld,weuseargmaxtoselecttheenhancementofgreatestrank.Anotherinterestingexampleistheuseofeffectsforobjectacqui-sition.InSection3ourunittypehadaeldtorepresentitscur-rentcombattarget,andweusedanobjecteffecteldwithapri-orityfunctiontoupdatethisvalue.Anotherexamplewouldbetheuseofanobjecteffecttoassignloottocharactersafterasuccess-fulbosskill.Lootassignmentpresentsaninterestingchallenge,sincewewanttoensurethatonlyonecharactergetstheobject.Typicallythisisnotanissues,asthegameprocesseseachplayerseparatelyinturn.However,whenweusethestate-effectpattern,playersmayprocessedsimultaneously,sowecannotcheckwhetheranotherplayerhasreceivedthelootinthesametimestep.Thesolutiontothisproblemistounderstandwhatoursemanticconstraintsare.Whileplayersmayhavemultipleitemsofloot,eachlootmayhaveonlyoneplayer.Becausetheuniquenessconstraintappliestothelootandnottheplayer,thecorrectdesigninthiscaseistomaketheowneraneffecteldinthelootobject.Thatwaytheloothasapriorityfunctionforchoosingitsuniqueownerinthecaseofties.Oncetheownerhasbeendetermined,theobjectcanbeaddedthecharacter'sinventoryeitherbytheupdaterules(SGLsupportsexpressionsformanipulatingsetsofobjects)orinasubsequentiterationoftheupdateloop.Withsomepractice,ourcurrentformulationofthestate-effectpat-terncanexpressawiderangeofeffectinteractions.Aswecontinuetoexploretheusesofthispattern,wemayndwaystoextendittoothertypesofeffectinteractions.Thisisaninterestingareaforfuturework.5.2IntegratingtheState-EffectPatternAnotherchallengewiththestate-effectpatternisinintegratingitwithotherpartsofthegameengine.Firstofall,wemustiden-tifywhatparts,ifany,ofthegameengineareamenabletothestate-effectpattern.Somesubsystemsareveryeasytomodelinthisframework,whileotherscannotbemodeledatall.Themostsignicantlimitationisthatwecannotusethispatternsearchoverthetransitiveclosureofagraph.ThismeansthatitcannotsupportpathndingalgorithmslikeA?whichcrawloveraterraingraph.Ontheotherhand,steeringalgorithms[Reynolds1999]aresimilartoforcecalculationsinaparticlesystemsandarequiteamenabletothestate-effectpattern.Therststepinthedesignprocessistoidentifyallinstancesofiter-ation,suchasfor-loopsorwhile-loops.Anyiterationwhichcanbeexpressedasafor-eachloop,orunrolledasaconstantnum-berofiterations,isacandidateforthequeryphase.However,wemustalsoexaminethevariableassignmentswithineachiterationloop.Theseassignmentsmustallbeexpressibleaseffectvariables;otherwisetheywillbelostwhentheiterationisdone.Obviouslywecandothiswhentheiterationissimpleaggregation(e.g.summing,averaging,buildingupsetsofobjects).Withgreaterprociencyineffectdesign,wearecapableofdoingmore.Forcasessuchaspathnding,whichcannotbemodeledbythispattern,westillmaybeabletoimproveperformancethroughmoresophisticateduseofthestate-effectpattern.Thestate-effectpatternassumesthatitispartofthemainsimulationloop.However,thereisnothingpreventingusfromembeddingthestate-effectpatterninotheriterationloopsaswell.InSGL,acallfromthegameengineonlyperformsasinglequeryphaseandupdate,allowingustopo-sitionitwhereeverwewant.Thuswecanapplythestate-effectpatterntotheinternalsofthesealgorithms,andtheniterateoverthispatternexternallyinthegameengine.However,thistypeofdesignmayrequirethatwereordertheap-plicationofiteration.Forexample,pathndingiteratesoverallofthecharacterssearchingforapath,and,foreachcharacter,usesA?toperformasearchoftheterraingraph.Theoutsideiterationisacceptable,whiletheinneriterationisnot.Wecanextendourstate-effectpatterntopathndingifweswaptheorderofiterations.Inthiscase,weusethequeryphasetopipelinetheprocessingofallofthecharactersatonce,anditerateoverthestepsintheA?algo-rithmoutsideinthepost-processingphase.Itisnotclearwhetherthisgivesanyperformancebenetoverexistinghigh-performancealgorithms,butitdoesillustratethebasicprinciple.Analternativetothisextensionofthestate-effectpattern,istosim-plyseparatetroublesomecalculationsandintegratethemintothepost-processingphase.Onceagain,pathndingisanexcellentex-ample,asmostgameenginesimplementitinaseparatesubsystemwhichcommunicatesthesetofcomputedwaypointstothesteeringalgorithms[O'BrienandStout2007].AsSGLsupportssetelds,wecaneasilypassthisinformationfromthepathndingsystemtothesteeringalgorithmsinthequeryphase.Furthermore,asitisaseparatesubsystem,wecaneitherprocessthepathndingduringthepost-processingphase,orasynchronouslyinaseparatethread.Therightdesignchoiceineachoftheseinstancesdependsupontheapplication.Whileweshouldalwaysbereluctanttomoveworkoutofthedeclarativequeryphase,sometimesitistherightthingtodo.Again,aswedevelopmoreprociencywiththestate-effectpattern,wewillbegintolearnmoreabouttheappropriatedesignchoicesinthiscase.6RelatedWorkTherehasbeensomeworkintheacademiccommunityonspecialpurposescriptinglanguagesforgames,suchastheScriptEaselan-guage[McNaughtonetal.2004].However,muchofthisworkhasfocusedontoolsthatmakedesignaccessibletoinexperiencedpro-grammers.Theworkinthispaperisdifferentinthatourscriptinglanguageisdevelopedforthesolepurposeofprocessingcomplexgamebehaviorefciently.Whilethereareotherspecialpurposelanguagesdesignedforimprovinggameperformance,suchasSim-bionic[Fuetal.2003]orNaughtyDog'sGOAL[Liebgold2008],ourapproachistherstonetoleveragedatabaseprocessingtech-niques.