Hello! I have a headless server build for my game. It runs on my VPS which is weak (single core and 1 GB of RAM). Now, my game allows users to create maps which is saved with JSON and big JSON files while loading on server can be very tough and causes the complete VPS to crash. My current deserializer script is:
extends Node
onready var level = get_tree().get_root().get_node("Game/Level")
onready var Game = get_tree().get_root().get_node("Game")
onready var Cone = preload("res://pref/Cone22.tscn")
onready var Sphere = preload("res://pref/Sphere.tscn")
onready var Wedge = preload("res://pref/Wedge.tscn")
onready var Cube = preload("res://pref/Cube.tscn")
onready var Cylinder = preload("res://pref/Cylinder.tscn")
func deserializeGame(game_data:Dictionary)->void :
Game.send_discord_message("START MAP INIT ON SERVER", "SERVER -> DESERIALIZER")
PhysicsServer.set_active(false)
var level_data = game_data["Level"]
var objects_data = level_data[0]["children"]
var startTime = OS.get_unix_time()
for object_data in objects_data:
var object_instance = deserializeObject(object_data)
level.add_child(object_instance)
var endTime = OS.get_unix_time() - startTime
func deserializeObject(Object_data):
var ToInstance
match Object_data.type:
"Cube":
ToInstance = Cube.instance()
"Sphere":
ToInstance = Sphere.instance()
"Cone":
ToInstance = Cone.instance()
"Wedge":
ToInstance = Wedge.instance()
"Cylinder":
ToInstance = Cylinder.instance()
"Script":
ToInstance = deserializeScript(Object_data)
_:
print("Error: Object type not found")
return null
var Meshe = ToInstance.get_node("MeshInstance")
var collision_shape = ToInstance.get_node("CollisionShape")
var newMat = SpatialMaterial.new()
newMat.albedo_color = Color(str(Object_data.color))
ToInstance.translation = Vector3(Object_data.position[0], Object_data.position[1], Object_data.position[2])
ToInstance.scale = Vector3(Object_data.size[0], Object_data.size[1], Object_data.size[2])
ToInstance.rotation_degrees = Vector3(Object_data.rotation[0], Object_data.rotation[1], Object_data.rotation[2])
if Object_data.color != "#NULL":
Meshe.set_surface_material(0, newMat)
var children_data = Object_data.children
for child_data in children_data:
var child_instance = deserializeObject(child_data)
ToInstance.add_child(child_instance)
return ToInstance
func deserializeScript(script):
pass
What should I do?