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._content = ChunkDiff()
|
||||||
self._modifications = ChunkDiff()
|
self._modifications = ChunkDiff()
|
||||||
|
|
||||||
|
self.last_modified = None
|
||||||
self.touch()
|
self.touch()
|
||||||
|
|
||||||
def set(self, x, y, character):
|
def set(self, x, y, character):
|
||||||
|
|
@ -125,9 +126,11 @@ class Chunk():
|
||||||
def commit_changes(self):
|
def commit_changes(self):
|
||||||
self.commit_diff(self._modifications)
|
self.commit_diff(self._modifications)
|
||||||
self._modifications = ChunkDiff()
|
self._modifications = ChunkDiff()
|
||||||
|
self.touch()
|
||||||
|
|
||||||
def apply_diff(self, diff):
|
def apply_diff(self, diff):
|
||||||
self._modifications.apply(diff)
|
self._modifications.apply(diff)
|
||||||
|
self.touch()
|
||||||
|
|
||||||
def commit_diff(self, diff):
|
def commit_diff(self, diff):
|
||||||
self._content.apply(diff)
|
self._content.apply(diff)
|
||||||
|
|
@ -136,6 +139,7 @@ class Chunk():
|
||||||
|
|
||||||
def drop_changes(self):
|
def drop_changes(self):
|
||||||
self._modifications = ChunkDiff()
|
self._modifications = ChunkDiff()
|
||||||
|
self.touch()
|
||||||
|
|
||||||
def get_changes(self):
|
def get_changes(self):
|
||||||
return self._modifications
|
return self._modifications
|
||||||
|
|
@ -191,16 +195,18 @@ class ChunkPool():
|
||||||
for dchunk in diffs:
|
for dchunk in diffs:
|
||||||
pos = dchunk[0]
|
pos = dchunk[0]
|
||||||
diff = dchunk[1]
|
diff = dchunk[1]
|
||||||
|
chunk = self.load(pos)
|
||||||
|
|
||||||
chunk = self.get(pos) or self.create(pos)
|
if not diff.empty():
|
||||||
chunk.apply_diff(diff)
|
chunk.apply_diff(diff)
|
||||||
|
|
||||||
def commit_diffs(self, diffs):
|
def commit_diffs(self, diffs):
|
||||||
for dchunk in diffs:
|
for dchunk in diffs:
|
||||||
pos = dchunk[0]
|
pos = dchunk[0]
|
||||||
diff = dchunk[1]
|
diff = dchunk[1]
|
||||||
|
chunk = self.load(pos)
|
||||||
|
|
||||||
chunk = self.get(pos) or self.create(pos)
|
if not diff.empty():
|
||||||
chunk.commit_diff(diff)
|
chunk.commit_diff(diff)
|
||||||
|
|
||||||
def commit_changes(self):
|
def commit_changes(self):
|
||||||
|
|
@ -216,12 +222,10 @@ class ChunkPool():
|
||||||
self.commit_changes()
|
self.commit_changes()
|
||||||
|
|
||||||
def load(self, pos):
|
def load(self, pos):
|
||||||
if not pos in self._chunks:
|
return self.get(pos) or self.create(pos)
|
||||||
self.create(pos)
|
|
||||||
|
|
||||||
def load_list(self, coords):
|
def load_list(self, coords):
|
||||||
for pos in coords:
|
for pos in coords:
|
||||||
if pos not in self._chunks:
|
|
||||||
self.load(pos)
|
self.load(pos)
|
||||||
|
|
||||||
def unload(self, pos):
|
def unload(self, pos):
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,6 @@ class ClientChunkPool(ChunkPool):
|
||||||
if diffs:
|
if diffs:
|
||||||
self._client.send_changes(diffs)
|
self._client.send_changes(diffs)
|
||||||
|
|
||||||
def load(self, pos):
|
|
||||||
raise Exception
|
|
||||||
|
|
||||||
def load_list(self, coords):
|
def load_list(self, coords):
|
||||||
coords = [pos for pos in coords if pos not in self._chunks]
|
coords = [pos for pos in coords if pos not in self._chunks]
|
||||||
if coords:
|
if coords:
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class WotServer(WebSocket):
|
||||||
with pool:
|
with pool:
|
||||||
for coor in coords:
|
for coor in coords:
|
||||||
pos = Position(coor[0], coor[1])
|
pos = Position(coor[0], coor[1])
|
||||||
chunk = pool.get(pos) or pool.create(pos)
|
chunk = pool.load(pos)
|
||||||
diffs.append((pos, chunk.as_diff()))
|
diffs.append((pos, chunk.as_diff()))
|
||||||
|
|
||||||
self.loaded_chunks.add(pos)
|
self.loaded_chunks.add(pos)
|
||||||
|
|
@ -65,7 +65,7 @@ class WotServer(WebSocket):
|
||||||
for dchunk in diffs:
|
for dchunk in diffs:
|
||||||
pos = dchunk[0]
|
pos = dchunk[0]
|
||||||
diff = dchunk[1]
|
diff = dchunk[1]
|
||||||
chunk = pool.get(pos) or pool.create(pos)
|
chunk = pool.load(pos)
|
||||||
reverse_diff = diff.diff(chunk.as_diff())
|
reverse_diff = diff.diff(chunk.as_diff())
|
||||||
reverse_diffs.append((pos, reverse_diff))
|
reverse_diffs.append((pos, reverse_diff))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue