Skip to content

Commit

Permalink
reduce memory feature
Browse files Browse the repository at this point in the history
  • Loading branch information
magicbear committed Feb 14, 2024
1 parent 103594b commit f22a7c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion palworld_server_toolkit/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ def read(
type_hints=type_hints,
custom_properties=custom_properties,
allow_nan=allow_nan,
reduce_memory=getattr(args, "reduce_memory", False)
) as reader:
skip_loading_progress(reader, len(data)).start()
gvas_file.header = GvasHeader.read(reader)
Expand Down Expand Up @@ -391,7 +392,8 @@ def parse_skiped_item(properties, skip_path, progress=True, recursive=True, mp=N

with FProgressArchiveReader(
writer.bytes(), PALWORLD_TYPE_HINTS,
localProperties
localProperties,
reduce_memory=getattr(args, "reduce_memory", False)
) as reader:
if progress:
skip_loading_progress(reader, len(properties['value'])).start()
Expand Down
9 changes: 7 additions & 2 deletions palworld_server_toolkit/palobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pickle
import msgpack
import ctypes
import sys


def toUUID(uuid_str):
Expand Down Expand Up @@ -578,6 +579,10 @@ class FProgressArchiveReader(FArchiveReader):
processlist = {}

def __init__(self, *args, **kwargs):
reduce_memory = False
if 'reduce_memory' in kwargs:
reduce_memory = kwargs['reduce_memory']
del kwargs['reduce_memory']
super().__init__(*args, **kwargs)
self.fallbackData = None
self.mp_loading = False
Expand All @@ -587,9 +592,9 @@ def __init__(self, *args, **kwargs):
if 'MemFree:' == line[0:8]:
remain = line.split(": ")[1].strip().split(" ")
if remain[1] == 'kB' and int(remain[0]) > 1048576 > 4: # Over 4 GB memory remains
self.mp_loading = False if getattr(args, "reduce_memory", False) else True
self.mp_loading = False if reduce_memory else True
elif sys.platform == 'darwin' or sys.platform == 'win32':
self.mp_loading = False if getattr(args, "reduce_memory", False) else True
self.mp_loading = False if reduce_memory else True

def progress(self):
return self.data.tell()
Expand Down

0 comments on commit f22a7c8

Please sign in to comment.