Update chunk logic
Correctly store time of last modification Use "load" to get a chunk (or load/create one if it isn't loaded)
This commit is contained in:
parent
d68d32ff2f
commit
4822cab0fc
3 changed files with 14 additions and 13 deletions
14
chunks.py
14
chunks.py
|
|
@ -112,6 +112,7 @@ class Chunk():
|
|||
self._content = ChunkDiff()
|
||||
self._modifications = ChunkDiff()
|
||||
|
||||
self.last_modified = None
|
||||
self.touch()
|
||||
|
||||
def set(self, x, y, character):
|
||||
|
|
@ -125,9 +126,11 @@ class Chunk():
|
|||
def commit_changes(self):
|
||||
self.commit_diff(self._modifications)
|
||||
self._modifications = ChunkDiff()
|
||||
self.touch()
|
||||
|
||||
def apply_diff(self, diff):
|
||||
self._modifications.apply(diff)
|
||||
self.touch()
|
||||
|
||||
def commit_diff(self, diff):
|
||||
self._content.apply(diff)
|
||||
|
|
@ -136,6 +139,7 @@ class Chunk():
|
|||
|
||||
def drop_changes(self):
|
||||
self._modifications = ChunkDiff()
|
||||
self.touch()
|
||||
|
||||
def get_changes(self):
|
||||
return self._modifications
|
||||
|
|
@ -191,16 +195,18 @@ class ChunkPool():
|
|||
for dchunk in diffs:
|
||||
pos = dchunk[0]
|
||||
diff = dchunk[1]
|
||||
chunk = self.load(pos)
|
||||
|
||||
chunk = self.get(pos) or self.create(pos)
|
||||
if not diff.empty():
|
||||
chunk.apply_diff(diff)
|
||||
|
||||
def commit_diffs(self, diffs):
|
||||
for dchunk in diffs:
|
||||
pos = dchunk[0]
|
||||
diff = dchunk[1]
|
||||
chunk = self.load(pos)
|
||||
|
||||
chunk = self.get(pos) or self.create(pos)
|
||||
if not diff.empty():
|
||||
chunk.commit_diff(diff)
|
||||
|
||||
def commit_changes(self):
|
||||
|
|
@ -216,12 +222,10 @@ class ChunkPool():
|
|||
self.commit_changes()
|
||||
|
||||
def load(self, pos):
|
||||
if not pos in self._chunks:
|
||||
self.create(pos)
|
||||
return self.get(pos) or self.create(pos)
|
||||
|
||||
def load_list(self, coords):
|
||||
for pos in coords:
|
||||
if pos not in self._chunks:
|
||||
self.load(pos)
|
||||
|
||||
def unload(self, pos):
|
||||
|
|
|
|||
|
|
@ -36,9 +36,6 @@ class ClientChunkPool(ChunkPool):
|
|||
if diffs:
|
||||
self._client.send_changes(diffs)
|
||||
|
||||
def load(self, pos):
|
||||
raise Exception
|
||||
|
||||
def load_list(self, coords):
|
||||
coords = [pos for pos in coords if pos not in self._chunks]
|
||||
if coords:
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class WotServer(WebSocket):
|
|||
with pool:
|
||||
for coor in coords:
|
||||
pos = Position(coor[0], coor[1])
|
||||
chunk = pool.get(pos) or pool.create(pos)
|
||||
chunk = pool.load(pos)
|
||||
diffs.append((pos, chunk.as_diff()))
|
||||
|
||||
self.loaded_chunks.add(pos)
|
||||
|
|
@ -65,7 +65,7 @@ class WotServer(WebSocket):
|
|||
for dchunk in diffs:
|
||||
pos = dchunk[0]
|
||||
diff = dchunk[1]
|
||||
chunk = pool.get(pos) or pool.create(pos)
|
||||
chunk = pool.load(pos)
|
||||
reverse_diff = diff.diff(chunk.as_diff())
|
||||
reverse_diffs.append((pos, reverse_diff))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue