您好,欢迎访问三七文档
--definesMAIN=1USE_TELNET=falseENCODE_SAVES=BRANCH~=devCHEATS_ENABLED=BRANCH==devSOUNDDEBUG_ENABLED=false--usedforA/Btestingandpreviewfeatures.GetsserializedintoandoutofsavegamesGameplayOptions={}--installourcrazyloader!localloadfn=function(modulename)--print(modulename,package.path)localerrmsg=localmodulepath=string.gsub(modulename,%.,/)forpathinstring.gmatch(package.path,([^;]+))dolocalfilename=string.gsub(path,%?,modulepath)filename=string.gsub(filename,\\,/)localresult=kleiloadlua(filename)ifresultthenreturnresultenderrmsg=errmsg..\n\tnofile'..filename..'(checkedwithcustomloader)endreturnerrmsgendtable.insert(package.loaders,1,loadfn)--patchthisfunctionbecauseNACLhasnofopenifTheSimthenfunctionloadfile(filename)filename=string.gsub(filename,.lua,)filename=string.gsub(filename,data/scripts/,)returnloadfn(filename)endendifPLATFORM==NACLthenpackage.loaders[2]=nilelseifPLATFORM==WIN32then--[[localsock=loadfile(data/scriptlibs/socket.lua)localmime=loadfile(data/scriptlibs/mime.lua)ifsockthensock()endifmimethenmime()endifsockandmimethenUSE_TELNET=trueend--]]endrequire(strict)--TheSim:UnloadAllPrefabs()require(mods)require(json)require(vector3)require(tuning)require(languages/language)require(strings)require(stringutil)require(constants)require(class)require(actions)require(debugtools)require(simutil)require(util)require(scheduler)require(stategraph)require(behaviourtree)require(prefabs)require(entityscript)require(profiler)require(recipes)require(brain)require(emitters)require(dumper)require(input)require(upsell)require(stats)require(frontend)require(fileutil)require(screens/scripterrorscreen)require(widget)require(image)require(text)require(textedit)require(standardcomponents)require(cameras\\followcamera)require(update)print(runningmain.lua\n)VERBOSITY_LEVEL=VERBOSITY.ERRORifCONFIGURATION~=ProductionthenVERBOSITY_LEVEL=VERBOSITY.DEBUGend--uncommentthislinetooverrideVERBOSITY_LEVEL=VERBOSITY.WARNINGfunctionPrint(msg_verbosity,...)ifmsg_verbosity=VERBOSITY_LEVELthenprint(...)endendmath.randomseed(TheSim:GetRealTime())TheCamera=FollowCamera()--instantiatethemixerlocalMixer=require(mixer)TheMixer=Mixer.Mixer()require(mixes)TheMixer:PushMix(start)---PREFABSANDENTITYINSTANTIATIONPrefabs={}localfunctionRegisterPrefabs(...)fork,vinipairs(arg)dolocalprefab=vprefab.modfns=ModManager:GetPrefabPostInitFns(prefab.name)Prefabs[prefab.name]=prefab--print(Register..tostring(prefab))endendfunctionLoadPrefabFile(filename)--print(Loadingprefabfile..filename)localfn=loadfile(filename)assert(fn,Couldnotloadfile..filename)iftype(fn)~=functionthenprint(Prefabfiledoesn'treturnacallablechunk..filename..:..fn)assert(false)endiffnthenRegisterPrefabs(fn())endendEnts={}AwakeEnts={}UpdatingEnts={}NewUpdatingEnts={}num_updating_ents=0NumEnts=0functionSpawnPrefabFromSim(name)name=string.sub(name,string.find(name,[^/]*$))name=string.lower(name)localprefab=Prefabs[name]ifprefab==nilthenprint(Can'tfindprefab..tostring(name))return-1endifprefabthenlocalinst=prefab.fn(TheSim)fork,modinpairs(prefab.modfns)domod(inst)endifinst~=nilthenifinst.AnimStatetheninst:AddComponent(highlight)endinst:SetPrefabName(inst.prefaborname)returninst.entity:GetGUID()elseprint(Failedtospawn,name)return-1endendendfunctionPrefabExists(name)returnPrefabs[name]~=nilendlocalrenames={feather=feather_crow,}functionSpawnPrefab(name)name=string.sub(name,string.find(name,[^/]*$))name=renames[name]ornamelocalguid=TheSim:SpawnPrefab(name)returnEnts[guid]endfunctionSpawnSaveRecord(saved,newents)--print(string.format(SpawnSaveRecord[%s,%s,%s],tostring(saved.id),tostring(saved.prefab),tostring(saved.data)))localinst=SpawnPrefab(saved.prefab)ifinsttheninst.Transform:SetPosition(saved.xor0,saved.yor0,saved.zor0)ifnewentsandsaved.idthennewents[saved.id]={entity=inst,data=saved.data}end--Attachscenario.Thisisaspecialcomponentthat'saddedbasedonsavedata,notprefabsetup.ifsaved.scenarioor(saved.dataandsaved.data.scenariorunner)thenifinst.components.scenariorunner==niltheninst:AddComponent(scenariorunner)endifsaved.scenariotheninst.components.scenariorunner:SetScript(saved.scenario)endendinst:SetPersistData(saved.data,newents)elseprint(string.format(SpawnSaveRecord[%s,%s]FAILED,tostring(saved.id),saved.prefab))endreturninstendfunctionCreateEntity()localent=TheSim:CreateEntity()localguid=ent:GetGUID()localscr=EntityScript(ent)Ents[guid]=scrNumEnts=NumEnts+1AwakeEnts[guid]=Ents[guid]returnscrendlocaldebug_entity=nilfunctionOnRemoveEntity(entityguid)localent=Ents[entityguid]ifentthenifdebug_entity==entthendebug_entity=nilendBrainManager:OnRemoveEntity(ent)SGManager:OnRemoveEntity(ent)ent:KillTasks()NumEnts=NumEnts-1Ents[entityguid]=nilifUpdatingEnts[entityguid]thenUpdatingEnts[entityguid]=nilnum_updating_ents=num_updating_ents-1endAwakeEnts[entityguid]=nilendendfunctionPushEntityEvent(guid,event,data)localinst=Ents[guid]ifinsttheninst:PushEvent(event,data)endend------TIMEFUNCTIONSfunctionGetTickTime()returnTheSim:GetTickTime()endlocalticktime=GetTickTime()functionGetTime()returnTheSim:GetTic
本文标题:main.lua
链接地址:https://www.777doc.com/doc-4770067 .html