Separated object and cache keys

This commit is contained in:
Skye Terran 2021-08-23 16:42:26 -07:00
parent bdd83df783
commit 60b94a426f
2 changed files with 44 additions and 33 deletions

View File

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28, "execution_count": 7,
"source": [ "source": [
"import json\r\n", "import json\r\n",
"\r\n", "\r\n",
@ -20,7 +20,8 @@
" \"assets\": {}\r\n", " \"assets\": {}\r\n",
" },\r\n", " },\r\n",
" \"internal\": {\r\n", " \"internal\": {\r\n",
" \"max_key\": 0\r\n", " \"max_object_key\": 0,\r\n",
" \"max_cache_key\": 0\r\n",
" }\r\n", " }\r\n",
" }\r\n", " }\r\n",
"\r\n", "\r\n",
@ -39,13 +40,23 @@
" with open(filename, \"w\") as outfile:\r\n", " with open(filename, \"w\") as outfile:\r\n",
" json.dump(clean_data, outfile, indent = 4)\r\n", " json.dump(clean_data, outfile, indent = 4)\r\n",
"\r\n", "\r\n",
"# get a new indexed object key and increment the scene's max key\r\n", "# get a new indexed object key and track it\r\n",
"def add_key(data):\r\n", "def object_key(data):\r\n",
" # get the indexed key\r\n", " # get the indexed key\r\n",
" key = hex(data[\"internal\"][\"max_key\"] + 1)\r\n", " key = hex(data[\"internal\"][\"max_object_key\"] + 1)\r\n",
"\r\n", "\r\n",
" # index the max key\r\n", " # index the max key\r\n",
" data[\"internal\"][\"max_key\"] += 1\r\n", " data[\"internal\"][\"max_object_key\"] += 1\r\n",
"\r\n",
" return key\r\n",
"\r\n",
"# get a new indexed cache key and track it\r\n",
"def cache_key(data):\r\n",
" # get the indexed key\r\n",
" key = hex(data[\"internal\"][\"max_cache_key\"] + 1)\r\n",
"\r\n",
" # index the max key\r\n",
" data[\"internal\"][\"max_cache_key\"] += 1\r\n",
"\r\n", "\r\n",
" return key\r\n", " return key\r\n",
"\r\n", "\r\n",
@ -57,7 +68,7 @@
" }\r\n", " }\r\n",
" \r\n", " \r\n",
" # add the asset to the graph\r\n", " # add the asset to the graph\r\n",
" data[\"graph\"][\"assets\"][add_key(data)] = (\"asset\", asset_data)\r\n", " data[\"graph\"][\"assets\"][object_key(data)] = (\"asset\", asset_data)\r\n",
"\r\n", "\r\n",
"# add an object to the scene\r\n", "# add an object to the scene\r\n",
"def spawn_object(data, name, asset):\r\n", "def spawn_object(data, name, asset):\r\n",
@ -73,14 +84,14 @@
" object_data[\"asset\"] = f\"*{key}\"\r\n", " object_data[\"asset\"] = f\"*{key}\"\r\n",
"\r\n", "\r\n",
" # add the object to the scene\r\n", " # add the object to the scene\r\n",
" data[\"graph\"][\"scene\"][add_key(data)] = (\"object\", object_data)" " data[\"graph\"][\"scene\"][object_key(data)] = (\"object\", object_data)"
], ],
"outputs": [], "outputs": [],
"metadata": {} "metadata": {}
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 29, "execution_count": 8,
"source": [ "source": [
"# cache the scene\r\n", "# cache the scene\r\n",
"def cache_scene(data):\r\n", "def cache_scene(data):\r\n",
@ -120,7 +131,7 @@
"\r\n", "\r\n",
" # create hash objects for each repeated value\r\n", " # create hash objects for each repeated value\r\n",
" for key, value in hash_cache.items():\r\n", " for key, value in hash_cache.items():\r\n",
" cache_pointer = f\"#{add_key(data)}\"\r\n", " cache_pointer = cache_key(data)\r\n",
" data[\"cache\"][cache_pointer] = value[\"value\"]\r\n", " data[\"cache\"][cache_pointer] = value[\"value\"]\r\n",
" hash_cache[key][\"pointer\"] = cache_pointer\r\n", " hash_cache[key][\"pointer\"] = cache_pointer\r\n",
"\r\n", "\r\n",
@ -134,14 +145,14 @@
"\r\n", "\r\n",
" # if this value is cached, replace it with its cache pointer\r\n", " # if this value is cached, replace it with its cache pointer\r\n",
" if value_hash in hash_cache:\r\n", " if value_hash in hash_cache:\r\n",
" objects[object_key][1][value_key] = hash_cache[value_hash][\"pointer\"]" " objects[object_key][1][value_key] = \"#\" + hash_cache[value_hash][\"pointer\"]"
], ],
"outputs": [], "outputs": [],
"metadata": {} "metadata": {}
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 30, "execution_count": 9,
"source": [ "source": [
"# just returns a random string\r\n", "# just returns a random string\r\n",
"import random\r\n", "import random\r\n",

View File

@ -20,10 +20,10 @@
{ {
"name": [ "name": [
"name", "name",
"MN7SY1DZ" "NO94Z37B"
], ],
"asset": "*0x1", "asset": "*0x1",
"trans": "#0x9" "trans": "#0x1"
} }
], ],
"0x5": [ "0x5": [
@ -31,10 +31,10 @@
{ {
"name": [ "name": [
"name", "name",
"JIZTJG2T" "NC302YU1"
], ],
"asset": "*0x3", "asset": "*0x2",
"trans": "#0x9" "trans": "#0x1"
} }
], ],
"0x6": [ "0x6": [
@ -42,10 +42,10 @@
{ {
"name": [ "name": [
"name", "name",
"78LMETC7" "GW5625SS"
], ],
"asset": "*0x2", "asset": "*0x3",
"trans": "#0x9" "trans": "#0x1"
} }
], ],
"0x7": [ "0x7": [
@ -53,10 +53,10 @@
{ {
"name": [ "name": [
"name", "name",
"4PEMWVMY" "THUUN5IN"
], ],
"asset": "*0x3", "asset": "*0x3",
"trans": "#0x9" "trans": "#0x1"
} }
], ],
"0x8": [ "0x8": [
@ -64,10 +64,10 @@
{ {
"name": [ "name": [
"name", "name",
"N553FJRY" "JT5FVYOW"
], ],
"asset": "*0x1", "asset": "*0x2",
"trans": "#0x9" "trans": "#0x1"
} }
] ]
}, },
@ -77,9 +77,9 @@
{ {
"name": [ "name": [
"name", "name",
"ONQSQMWX" "3QDJ22P1"
], ],
"file": "#0xa" "file": "#0x2"
} }
], ],
"0x2": [ "0x2": [
@ -87,9 +87,9 @@
{ {
"name": [ "name": [
"name", "name",
"GTIRGEOQ" "49ITSLZI"
], ],
"file": "#0xa" "file": "#0x2"
} }
], ],
"0x3": [ "0x3": [
@ -97,15 +97,15 @@
{ {
"name": [ "name": [
"name", "name",
"DA6GXN8J" "O6YSH0DS"
], ],
"file": "#0xa" "file": "#0x2"
} }
] ]
} }
}, },
"cache": { "cache": {
"#0x9": [ "0x1": [
"trans", "trans",
[ [
[ [
@ -125,7 +125,7 @@
] ]
] ]
], ],
"#0xa": [ "0x2": [
"path", "path",
"Assets/TestAsset.obj" "Assets/TestAsset.obj"
] ]