Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Navigation
- class Request:
- var start = Vector3()
- var end = Vector3()
- var agent = null
- func _init(start,end,agent):
- self.start = start
- self.end = end
- self.agent = agent
- class Result:
- var path = []
- var agent = null
- func _init(path, agent):
- self.path = path
- self.agent = agent
- var threads = []
- var mutex = Mutex.new()
- func requestThread():
- if threads.size() == 0:
- threads.append(Thread.new())
- print("Threads : ",threads.size())
- for thread in threads:
- if !thread.is_active():
- return thread
- var newThread = Thread.new()
- threads.append(newThread)
- return newThread
- func onRequestPath(agent,start,end):
- var request = Request.new(start,end,agent)
- var thread = requestThread()
- #!!
- mutex.lock()
- thread.start(self,"loadPath",request)
- func loadPath(request):
- var path = get_simple_path(request.start,request.end,true)
- call_deferred("loadDone")
- var r = Result.new(path,request.agent)
- return r
- func loadDone():
- #!!
- mutex.unlock()
- #Does this makes any sense ?
- for thread in threads:
- if thread.is_active():
- var result = thread.wait_to_finish()
- result.agent.setPath(result.path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement