optimizations
This commit is contained in:
parent
c1c7fd1b43
commit
5ad58e905d
|
@ -6,6 +6,7 @@ os.environ["SSL_CERT_FILE"] = certifi.where()
|
||||||
|
|
||||||
from typing import List
|
from typing import List
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
from quarry.net.server import ServerFactory, ServerProtocol
|
from quarry.net.server import ServerFactory, ServerProtocol
|
||||||
|
@ -187,14 +188,20 @@ class Player:
|
||||||
def load_chunk(self, x: int, z: int):
|
def load_chunk(self, x: int, z: int):
|
||||||
print(f"enqueuing loading chunk {x}, {z}")
|
print(f"enqueuing loading chunk {x}, {z}")
|
||||||
self._chunks.add((x,z))
|
self._chunks.add((x,z))
|
||||||
self._load_queue.append((x,z))
|
if (x,z) not in self._load_queue:
|
||||||
|
self._load_queue.append((x,z))
|
||||||
|
if (x,z) in self._unload_queue:
|
||||||
|
self._unload_queue.remove((x,z))
|
||||||
# self._conn.send_chunk(x,z)
|
# self._conn.send_chunk(x,z)
|
||||||
|
|
||||||
def unload_chunk(self, x: int, z: int):
|
def unload_chunk(self, x: int, z: int):
|
||||||
print(f"enqueuing unloading chunk {x}, {z}")
|
print(f"enqueuing unloading chunk {x}, {z}")
|
||||||
try: self._chunks.remove((x,z))
|
try: self._chunks.remove((x,z))
|
||||||
except KeyError: pass
|
except KeyError: pass
|
||||||
self._unload_queue.append((x,z))
|
if (x,z) not in self._unload_queue:
|
||||||
|
self._unload_queue.append((x,z))
|
||||||
|
if (x,z) in self._load_queue:
|
||||||
|
self._load_queue.remove((x,z))
|
||||||
# self._conn.send_unload_chunk(x,z)
|
# self._conn.send_unload_chunk(x,z)
|
||||||
|
|
||||||
|
|
||||||
|
@ -300,12 +307,14 @@ class YTDServerProtocol(ServerProtocol):
|
||||||
self.send_packet("join_game", *join_game)
|
self.send_packet("join_game", *join_game)
|
||||||
|
|
||||||
def manage_queue(self):
|
def manage_queue(self):
|
||||||
|
t = time.time()
|
||||||
if self.player._load_queue:
|
if self.player._load_queue:
|
||||||
x,z = self.player._load_queue.pop(0)
|
x,z = self.player._load_queue.pop(0)
|
||||||
while (x,z) in self.player._load_queue:
|
while (x,z) in self.player._load_queue:
|
||||||
self.player._load_queue.remove((x,z))
|
self.player._load_queue.remove((x,z))
|
||||||
print(f"dequeuing loading chunk {x}, {z}")
|
print(f"dequeuing loading chunk {x}, {z}")
|
||||||
self.send_chunk(x,z)
|
self.send_chunk(x,z)
|
||||||
|
print(f"generating {x}, {z} took {int(time.time()-t)}s")
|
||||||
elif self.player._unload_queue:
|
elif self.player._unload_queue:
|
||||||
x,z = self.player._unload_queue.pop(0)
|
x,z = self.player._unload_queue.pop(0)
|
||||||
while (x,z) in self.player._unload_queue:
|
while (x,z) in self.player._unload_queue:
|
||||||
|
|
Loading…
Reference in New Issue