Implement parts of clientchunkpool and fix softlock in the process

This commit is contained in:
Joscha 2017-04-09 09:52:11 +00:00
parent c5af7c2480
commit 23da1ea5d9
5 changed files with 90 additions and 31 deletions

View file

@ -1,6 +1,6 @@
import threading
import time
from utils import CHUNK_WIDTH, CHUNK_HEIGHT
from utils import CHUNK_WIDTH, CHUNK_HEIGHT, Position
class ChunkDiff():
"""
@ -134,14 +134,28 @@ class ChunkPool():
def __exit__(self, type, value, tb):
self._lock.release()
def set(self, pos, chunk):
self._chunks[pos] = chunk
def get(self, pos):
return self._chunks.get(pos)
def create(self, pos):
chunk = Chunk()
self._chunks[pos] = chunk
self.set(pos, chunk)
return chunk
def apply_changes(self, changes):
for change in changes:
pos = Position(change[0][0], change[0][1])
diff = change[1]
chunk = self.get(pos)
if not chunk:
chunk = self.create(pos)
chunk.commit_diff(diff)
def commit_changes(self):
changes = []
@ -174,6 +188,8 @@ class ChunkPool():
# old list comprehension which became too long:
#coords = [pos for pos, chunk in self._chunks.items() if not pos in except_for and condition(chunk)]
self.save_changes()
coords = []
for pos, chunk in self._chunks.items():