diff --git a/fastbuilder/environment/environment.go b/fastbuilder/environment/environment.go index 207165848..69c1b405e 100644 --- a/fastbuilder/environment/environment.go +++ b/fastbuilder/environment/environment.go @@ -37,6 +37,8 @@ type PBEnvironment struct { CertSigning bool LocalKey string LocalCert string + LRUMemoryChunkCacher interface{} + ChunkFeeder interface{} } func (env *PBEnvironment) Stop() { diff --git a/io/special_tasks/export.go b/io/special_tasks/export.go index 843fb8152..0257124ab 100644 --- a/io/special_tasks/export.go +++ b/io/special_tasks/export.go @@ -19,6 +19,7 @@ import ( "phoenixbuilder/minecraft" "phoenixbuilder/minecraft/protocol" "phoenixbuilder/minecraft/protocol/packet" + "phoenixbuilder/mirror/io/lru" "phoenixbuilder/mirror/chunk" "runtime" "strconv" @@ -78,7 +79,7 @@ func CreateExportTask(commandLine string, env *environment.PBEnvironment) *task. hopPath,requiredChunks:=fetcher.PlanHopSwapPath(startX,startZ,endX,endZ,16) chunkPool:=map[fetcher.ChunkPosDefine]fetcher.ChunkDefine{} memoryCacheFetcher:=fetcher.CreateCacheHitFetcher(requiredChunks,chunkPool) - global.GlobalLRUMemoryChunkCacher.Iter(func(pos define.ChunkPos, chunk *mirror.ChunkData) (stop bool) { + env.LRUMemoryChunkCacher.(*lru.LRUMemoryChunkCacher).Iter(func(pos define.ChunkPos, chunk *mirror.ChunkData) (stop bool) { memoryCacheFetcher(fetcher.ChunkPosDefine{int(pos[0])*16,int(pos[1])*16},fetcher.ChunkDefine(chunk)) return false }) @@ -93,7 +94,7 @@ func CreateExportTask(commandLine string, env *environment.PBEnvironment) *task. cmdsender.SendCommand(cmd,uid) } feedChan:=make(chan *fetcher.ChunkDefineWithPos,1024) - deRegFn:=global.GlobalChunkFeeder.RegNewReader(func (chunk *mirror.ChunkData) { + deRegFn:=env.ChunkFeeder.(*global.ChunkFeeder).RegNewReader(func (chunk *mirror.ChunkData) { feedChan<-&fetcher.ChunkDefineWithPos{Chunk: fetcher.ChunkDefine(chunk),Pos:fetcher.ChunkPosDefine{int(chunk.ChunkPos[0])*16,int(chunk.ChunkPos[1])*16}} }) inHopping:=true diff --git a/main.go b/main.go index 735d751d5..4bb64306e 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,7 @@ import ( "phoenixbuilder/minecraft/protocol/packet" "phoenixbuilder/mirror/io/assembler" "phoenixbuilder/mirror/io/global" + "phoenixbuilder/mirror/io/lru" "phoenixbuilder/omega/cli/embed" "phoenixbuilder/omega/suggest" "runtime" @@ -201,19 +202,12 @@ func create_environment() *environment.PBEnvironment { env.ScriptBridge = hostBridgeGamma scriptHolder := script_holder.InitScriptHolder(env) env.ScriptHolder = scriptHolder - /*if args.StartupScript() == "" { - hostBridgeGamma.HostRemoveBlock() - } else { - if scriptHolder.LoadScript(args.StartupScript(), env) { - hostBridgeGamma.HostWaitScriptBlock() - } else { - hostBridgeGamma.HostRemoveBlock() - } - }*/ if args.StartupScript() != "" { scriptHolder.LoadScript(args.StartupScript(), env) } hostBridgeGamma.HostRemoveBlock() + env.LRUMemoryChunkCacher=lru.NewLRUMemoryChunkCacher(12) + env.ChunkFeeder=global.NewChunkFeeder() return env } @@ -668,8 +662,8 @@ func runClient(env *environment.PBEnvironment) { chunkData := chunkAssembler.OnNewSubChunk(p) if chunkData != nil { // fmt.Println("new chunk") - global.GlobalChunkFeeder.OnNewChunk(chunkData) - global.GlobalLRUMemoryChunkCacher.Write(chunkData) + env.ChunkFeeder.(*global.ChunkFeeder).OnNewChunk(chunkData) + env.LRUMemoryChunkCacher.(*lru.LRUMemoryChunkCacher).Write(chunkData) // if env.OmegaAdaptorHolder != nil { // fmt.Println("new chunk") // env.OmegaAdaptorHolder.(*embed.EmbeddedAdaptor).FeedChunkData(chunkData) diff --git a/mirror/io/global/feeder.go b/mirror/io/global/feeder.go index 9c9b623b4..5003b8f96 100644 --- a/mirror/io/global/feeder.go +++ b/mirror/io/global/feeder.go @@ -45,6 +45,6 @@ func (o *ChunkFeeder) RegNewReader(fn ChunkWriteFn) (unRegFn func()) { } } -func init() { +/*func init() { GlobalChunkFeeder = NewChunkFeeder() -} +}*/ diff --git a/mirror/io/global/vars.go b/mirror/io/global/vars.go index cc5bc6ca4..80b86579c 100644 --- a/mirror/io/global/vars.go +++ b/mirror/io/global/vars.go @@ -2,15 +2,6 @@ package global import ( "phoenixbuilder/mirror" - "phoenixbuilder/mirror/io/lru" ) -type ChunkWriteFn func(chunk *mirror.ChunkData) - -var GlobalLRUMemoryChunkCacher *lru.LRUMemoryChunkCacher -var GlobalChunkFeeder *ChunkFeeder - -func init() { - GlobalLRUMemoryChunkCacher = lru.NewLRUMemoryChunkCacher(12) - GlobalChunkFeeder = NewChunkFeeder() -} +type ChunkWriteFn func(chunk *mirror.ChunkData) \ No newline at end of file