Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"files.associations": {
"vector": "cpp",
"algorithm": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"cfenv": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"coroutine": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"deque": "cpp",
"exception": "cpp",
"execution": "cpp",
"expected": "cpp",
"filesystem": "cpp",
"format": "cpp",
"forward_list": "cpp",
"fstream": "cpp",
"functional": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"numeric": "cpp",
"optional": "cpp",
"ostream": "cpp",
"queue": "cpp",
"random": "cpp",
"ranges": "cpp",
"ratio": "cpp",
"regex": "cpp",
"set": "cpp",
"shared_mutex": "cpp",
"span": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"string": "cpp",
"system_error": "cpp",
"thread": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"utility": "cpp",
"valarray": "cpp",
"variant": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ func _is_any_node_ancestor(node: Node, possible_ancestors: Array) -> bool:


func create_tree_item_for_node(node: Node) -> void:
if Zone.is_host():
return # not required on server
if _is_node_map(node):
recursively_populate_tree(node, get_root().get_child(_TopLevelItemIndices.MAPS))
else:
Expand Down
18 changes: 2 additions & 16 deletions mirror-godot-app/scripts/autoload/zone/server.gd
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func _refresh_space_objects_with_asset_id(asset_id: String, asset_data: Dictiona
if space_obj:
space_obj.on_asset_received(asset_data)


func _on_space_partial_update_received(update: Dictionary) -> void:
for spath in update["partial_data"]:
Zone.receive_space_update(spath, update["partial_data"][spath])
Expand Down Expand Up @@ -613,21 +613,7 @@ func _server_send_sync_space(client_peer_id_to_sync: int) -> void:


func _get_unique_space_objects_sorted_by_dst_to_spawn() -> Array:
var all_objs: Array = Zone.space_objects.duplicate()
var no_duplicates = []
for index in range(all_objs.size()):
var dup_exists_after = false
for sub_index in range(index + 1, all_objs.size()):
if all_objs[index]["_id"] == all_objs[sub_index]["_id"]:
# To prevent the client ingesting invalid objects that have been duplicated. It alleviates the issue for now and lets us release.
# If they get to the client nothing works properly. I will fix this in a follow up PR properly.
push_error("Duplicate ID found in the server list of objects, I have skipped it: ", all_objs[index]["_id"])
dup_exists_after = true
break
if not dup_exists_after:
no_duplicates.append(all_objs[index])
no_duplicates.sort_custom(_sort_by_dst_to_origin)
return no_duplicates
return Zone.space_objects


func _sort_by_dst_to_origin(in_a, in_b):
Expand Down
21 changes: 21 additions & 0 deletions mirror-godot-app/scripts/net/file_cache.gd
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,22 @@ func get_file_path(file_name: String) -> String:
var storage_path_format = Util.get_files_directory_path() + "%s"
return storage_path_format % file_name

# Retrieve a file hash
static func get_file_hash(file_path: String) -> String:
var ctx = HashingContext.new()
ctx.start(HashingContext.HASH_SHA1)
var file = FileAccess.open(file_path, FileAccess.READ)
while not file.eof_reached():
ctx.update(file.get_buffer(4096))
var res = ctx.finish()
var hash_string: String = res.hex_encode()
return hash_string

## Tries to load a file into memory from disk cache and returns the payload or null.
## TODO: CACHE

var duplicate_load_from_cache = {}

func try_load_cached_file(cache_key: String) -> Variant:
cache_key = cache_key.uri_decode()
if not _storage_cache.has(cache_key):
Expand All @@ -126,6 +140,13 @@ func try_load_cached_file(cache_key: String) -> Variant:
var file_path: String = get_file_path(file_name)
if not FileAccess.file_exists(file_path):
return null
#var file_hash: String = get_file_hash(file_path)
#if duplicate_load_from_cache.has(file_hash):
#duplicate_load_from_cache[file_hash].count +=1
#print("Attempted to load file from OS multiple times: ", duplicate_load_from_cache[file_hash].count)
#else:
#duplicate_load_from_cache[file_hash] = { "count": 1 }
#print("No duplicate yet: ", file_hash)
if Util.path_is_model(file_path):
return TMFileUtil.load_gltf_file_as_node(file_path, Zone.is_host())
elif Util.path_is_image(file_path):
Expand Down
7 changes: 7 additions & 0 deletions mirror-godot-app/scripts/net/zone_socket.gd
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,15 @@ func get_space_objects_page(space_id: String, page: int=1) -> void:
_requests.push_back(request)


var _duplicate_request = {}
func queue_download_asset(asset_id: String) -> Promise:
if _duplicate_request.has(asset_id):
var duplication_count = _duplicate_request[asset_id].count
_duplicate_request[asset_id].count += 1
print("Duplicate asset found: duplicate count: ", duplication_count)
return _duplicate_request[asset_id].promise
var promise: Promise = Promise.new()
_duplicate_request[asset_id] = { "count": 1, "promise": promise }
var event_id: String = UUID.generate_guid()
var request = {
"event": ZONE_GET_ASSET,
Expand Down
3 changes: 3 additions & 0 deletions scripts/compile-profiling.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd godot-engine
# we enable a compile database so we can easily debug in vscode and or other tools
scons target=editor optimize=speed_trace debug_symbols=yes compiledb=yes tracy_enable=yes