Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Move global vars to environment.
Browse files Browse the repository at this point in the history
  • Loading branch information
LNSSPsd committed Jul 22, 2022
1 parent cb99f8b commit d91a0bf
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 25 deletions.
2 changes: 2 additions & 0 deletions fastbuilder/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type PBEnvironment struct {
CertSigning bool
LocalKey string
LocalCert string
LRUMemoryChunkCacher interface{}
ChunkFeeder interface{}
}

func (env *PBEnvironment) Stop() {
Expand Down
5 changes: 3 additions & 2 deletions io/special_tasks/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"phoenixbuilder/minecraft"
"phoenixbuilder/minecraft/protocol"
"phoenixbuilder/minecraft/protocol/packet"
"phoenixbuilder/mirror/io/lru"
"phoenixbuilder/mirror/chunk"
"runtime"
"strconv"
Expand Down Expand Up @@ -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
})
Expand All @@ -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
Expand Down
16 changes: 5 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions mirror/io/global/feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ func (o *ChunkFeeder) RegNewReader(fn ChunkWriteFn) (unRegFn func()) {
}
}

func init() {
/*func init() {
GlobalChunkFeeder = NewChunkFeeder()
}
}*/
11 changes: 1 addition & 10 deletions mirror/io/global/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit d91a0bf

Please sign in to comment.