roamwright 0.61.1 → 0.61.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -10
- package/package.json +2 -1
- package/scripts/dev-engine.py +104 -0
- package/scripts/serve.py +187 -11
- package/scripts/world.mk +3 -1
package/README.md
CHANGED
|
@@ -92,16 +92,17 @@ renderer.render(scene, camera);
|
|
|
92
92
|
|
|
93
93
|
Import modules by path, for example `roamwright/geometry/builder.js`. Browse the [API reference](https://enestaylan.github.io/roamwright/docs/) for signatures, usage notes and source links.
|
|
94
94
|
|
|
95
|
-
| Area | Main modules
|
|
96
|
-
| ------------------------ |
|
|
97
|
-
| Seeded generation | `math/noise.js`, `math/random.js`
|
|
98
|
-
| Geometry and terrain | `geometry/builder.js`, `geometry/heightfield.js`, `geometry/terrain-chunks.js`
|
|
99
|
-
| Static geometry assembly | `geometry/builder-frame.js`, `geometry/builder-cells.js`, `geometry/part-ranges.js`
|
|
100
|
-
| Rendering | `rendering/context.js`, `rendering/sky.js`, `rendering/water-material.js`
|
|
101
|
-
| Interiors | `geometry/room-kit.js`, `rendering/room-materials.js`, `rendering/room-space.js`, `rendering/room-light.js`
|
|
102
|
-
| Movement | `motion/player.js`, `motion/biped-stride.js`
|
|
103
|
-
| Scene playback | `runtime/cue-cursor.js`, `rendering/camera-track.js`
|
|
104
|
-
| Background jobs | `runtime/pool.js`, `runtime/worker.js`, `runtime/grid-rows.js`
|
|
95
|
+
| Area | Main modules |
|
|
96
|
+
| ------------------------ | ----------------------------------------------------------------------------------------------------------------- |
|
|
97
|
+
| Seeded generation | `math/noise.js`, `math/random.js` |
|
|
98
|
+
| Geometry and terrain | `geometry/builder.js`, `geometry/heightfield.js`, `geometry/terrain-chunks.js` |
|
|
99
|
+
| Static geometry assembly | `geometry/builder-frame.js`, `geometry/builder-cells.js`, `geometry/part-ranges.js` |
|
|
100
|
+
| Rendering | `rendering/context.js`, `rendering/sky.js`, `rendering/water-material.js` |
|
|
101
|
+
| Interiors | `geometry/room-kit.js`, `rendering/room-materials.js`, `rendering/room-space.js`, `rendering/room-light.js` |
|
|
102
|
+
| Movement | `motion/player.js`, `motion/biped-stride.js` |
|
|
103
|
+
| Scene playback | `runtime/cue-cursor.js`, `rendering/camera-track.js` |
|
|
104
|
+
| Background jobs | `runtime/pool.js`, `runtime/worker.js`, `runtime/grid-rows.js` |
|
|
105
|
+
| A world's toolchain | `scripts/world.mk` (make recipes), `scripts/serve.py` (local server), `scripts/dev-engine.py` (unreleased engine) |
|
|
105
106
|
|
|
106
107
|
## Contributing and license
|
|
107
108
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "roamwright",
|
|
3
|
-
"version": "0.61.
|
|
3
|
+
"version": "0.61.2",
|
|
4
4
|
"description": "A procedural worldbuilding engine built on top of Three.js. Generate landscapes with rivers and changing weather, animate crowds, and explore on foot or in flight.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"threejs",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"tools",
|
|
49
49
|
"examples",
|
|
50
50
|
"scripts/serve.py",
|
|
51
|
+
"scripts/dev-engine.py",
|
|
51
52
|
"scripts/format.sh",
|
|
52
53
|
"scripts/lint.sh",
|
|
53
54
|
"scripts/check-app.sh",
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Install a development snapshot of Roamwright into a world's checkout without changing its lockfile.
|
|
2
|
+
|
|
3
|
+
ROAMWRIGHT=<selection> python3 <engine>/scripts/dev-engine.py run from the world's root (`make dev-engine` does)
|
|
4
|
+
|
|
5
|
+
The selection is `local` (the world's embedded `./roamwright/` worktree, else a `roamwright` checkout beside the world's main
|
|
6
|
+
checkout), `github` or `github:<ref>` (a shallow fetch of the engine's repository), or a path to an engine checkout. The
|
|
7
|
+
snapshot is packed and installed over `node_modules/roamwright`; a fingerprint of the source's commit and uncommitted changes
|
|
8
|
+
skips the install when nothing changed since the last one.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import hashlib
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
import subprocess
|
|
15
|
+
import tempfile
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
ROOT = Path.cwd() # the world's root: this file runs from the installed engine, not from the world
|
|
19
|
+
UPSTREAM = "https://github.com/enestaylan/roamwright.git"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def run(*args, cwd=ROOT):
|
|
23
|
+
return subprocess.check_output(args, cwd=cwd, text=True).strip()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def source_for(selection, scratch):
|
|
27
|
+
if selection == "local":
|
|
28
|
+
embedded = ROOT / "roamwright"
|
|
29
|
+
if (embedded / "package.json").is_file():
|
|
30
|
+
return embedded
|
|
31
|
+
common = Path(run("git", "rev-parse", "--path-format=absolute", "--git-common-dir"))
|
|
32
|
+
return common.parent.parent / "roamwright"
|
|
33
|
+
if selection == "github" or selection.startswith("github:"):
|
|
34
|
+
ref = selection.partition(":")[2] or "main"
|
|
35
|
+
checkout = scratch / "source"
|
|
36
|
+
run("git", "init", "-q", checkout)
|
|
37
|
+
run("git", "fetch", "-q", "--depth=1", "--", UPSTREAM, ref, cwd=checkout)
|
|
38
|
+
run("git", "checkout", "-q", "--detach", "FETCH_HEAD", cwd=checkout)
|
|
39
|
+
return checkout
|
|
40
|
+
return Path(selection).expanduser().resolve()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def source_fingerprint(source):
|
|
44
|
+
if not (source / ".git").exists():
|
|
45
|
+
return None
|
|
46
|
+
digest = hashlib.sha256()
|
|
47
|
+
digest.update(str(source.resolve()).encode("utf-8"))
|
|
48
|
+
digest.update(b"\0")
|
|
49
|
+
digest.update(run("git", "rev-parse", "HEAD", cwd=source).encode("utf-8"))
|
|
50
|
+
digest.update(b"\0")
|
|
51
|
+
status = run("git", "status", "--porcelain", cwd=source)
|
|
52
|
+
digest.update(status.encode("utf-8"))
|
|
53
|
+
if status:
|
|
54
|
+
digest.update(b"\0")
|
|
55
|
+
digest.update(subprocess.check_output(("git", "diff", "HEAD"), cwd=source))
|
|
56
|
+
untracked = run("git", "ls-files", "--others", "--exclude-standard", cwd=source)
|
|
57
|
+
for rel in untracked.splitlines():
|
|
58
|
+
target = source / rel
|
|
59
|
+
if target.is_file():
|
|
60
|
+
digest.update(b"\0" + rel.encode("utf-8") + b"\0")
|
|
61
|
+
digest.update(target.read_bytes())
|
|
62
|
+
return digest.hexdigest()
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def main():
|
|
66
|
+
selection = os.environ["ROAMWRIGHT"]
|
|
67
|
+
with tempfile.TemporaryDirectory(prefix="roamwright-dev-") as directory:
|
|
68
|
+
scratch = Path(directory)
|
|
69
|
+
source = source_for(selection, scratch)
|
|
70
|
+
if not (source / "package.json").is_file() or json.loads((source / "package.json").read_text())["name"] != "roamwright":
|
|
71
|
+
raise SystemExit(f"No Roamwright package at {source}")
|
|
72
|
+
stamp = ROOT / "node_modules/.roamwright-dev"
|
|
73
|
+
installed_pkg = ROOT / "node_modules/roamwright/package.json"
|
|
74
|
+
fingerprint = source_fingerprint(source)
|
|
75
|
+
if fingerprint and installed_pkg.is_file() and stamp.is_file() and stamp.read_text().strip() == fingerprint:
|
|
76
|
+
return
|
|
77
|
+
(packed,) = json.loads(run("npm", "pack", "--ignore-scripts", "--json", "--pack-destination", scratch, cwd=source))
|
|
78
|
+
# Invalidate the locked-release stamp before overlaying node_modules/roamwright so a plain `make build`
|
|
79
|
+
# in checkouts without `./roamwright/` restores package-lock.json cleanly.
|
|
80
|
+
(ROOT / "node_modules/.roamwright-installed").unlink(missing_ok=True)
|
|
81
|
+
stamp.unlink(missing_ok=True)
|
|
82
|
+
subprocess.run(
|
|
83
|
+
[
|
|
84
|
+
"npm",
|
|
85
|
+
"install",
|
|
86
|
+
"--include=dev",
|
|
87
|
+
"--no-save",
|
|
88
|
+
"--package-lock=false",
|
|
89
|
+
"--ignore-scripts",
|
|
90
|
+
"--no-audit",
|
|
91
|
+
"--no-fund",
|
|
92
|
+
scratch / packed["filename"],
|
|
93
|
+
],
|
|
94
|
+
cwd=ROOT,
|
|
95
|
+
check=True,
|
|
96
|
+
)
|
|
97
|
+
if fingerprint:
|
|
98
|
+
stamp.write_text(fingerprint + "\n")
|
|
99
|
+
revision = run("git", "rev-parse", "--short", "HEAD", cwd=source) if (source / ".git").exists() else ""
|
|
100
|
+
print(f"Using {packed['id']} from {selection} {revision} ({packed['integrity']})")
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
if __name__ == "__main__":
|
|
104
|
+
main()
|
package/scripts/serve.py
CHANGED
|
@@ -1,27 +1,203 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""The local server for a world's built page and for the engine's examples and browser fixtures.
|
|
2
2
|
|
|
3
|
+
python3 scripts/serve.py [port] serve the current folder (port 0: any free port, printed on the first line)
|
|
4
|
+
|
|
5
|
+
It serves the current folder's files, gzipped when the client accepts it, each checked afresh on every load. An address of
|
|
6
|
+
the page that is no file (`location/harbour`, with no dot in its last part) is sent back to the page as `?r=<address>`, the
|
|
7
|
+
same as the published site's 404 page (`scripts/site.mjs`): to the nearest folder above it that holds an `index.html`, so a
|
|
8
|
+
second build served from a subfolder (a worktree, a published base such as `/world/`) keeps its own page.
|
|
9
|
+
|
|
10
|
+
Environment, all optional:
|
|
11
|
+
SERVE_ROUTE_PARAM the query parameter a page reads its address from (default `r`; empty: no fallback, a plain 404)
|
|
12
|
+
SERVE_ENTRY=<query> send every request for the page itself to `/?<query>`, whatever address was asked for, and keep
|
|
13
|
+
nothing in the browser's cache: the iOS Simulator's browser (`tools/ios-sim.sh`) restores its last
|
|
14
|
+
tab without asking the server and cannot be handed an address without a tap
|
|
15
|
+
SERVE_STAMP under SERVE_ENTRY, the page's script addresses not named by their contents, comma-separated, that are
|
|
16
|
+
given a `?v=<start time>` so a restored tab cannot run another build's copy
|
|
17
|
+
(default `./app/main.js,./app/worker.js`)
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import gzip
|
|
21
|
+
import os
|
|
3
22
|
import sys
|
|
23
|
+
import threading
|
|
24
|
+
import time
|
|
4
25
|
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
from urllib.parse import quote, urlsplit
|
|
28
|
+
|
|
29
|
+
ROUTE_PARAM = os.environ.get("SERVE_ROUTE_PARAM", "r")
|
|
30
|
+
ENTRY = os.environ.get("SERVE_ENTRY", "")
|
|
31
|
+
UNSTAMPED = tuple(
|
|
32
|
+
f'"{name.strip()}"'.encode() for name in os.environ.get("SERVE_STAMP", "./app/main.js,./app/worker.js").split(",") if name.strip()
|
|
33
|
+
)
|
|
34
|
+
STAMP = str(int(time.time())).encode()
|
|
35
|
+
GZIP_EXTENSIONS = {
|
|
36
|
+
".cjs",
|
|
37
|
+
".css",
|
|
38
|
+
".htm",
|
|
39
|
+
".html",
|
|
40
|
+
".js",
|
|
41
|
+
".json",
|
|
42
|
+
".md",
|
|
43
|
+
".mjs",
|
|
44
|
+
".svg",
|
|
45
|
+
".txt",
|
|
46
|
+
".webmanifest",
|
|
47
|
+
".xml",
|
|
48
|
+
".yaml",
|
|
49
|
+
".yml",
|
|
50
|
+
}
|
|
51
|
+
GZIP_CACHE_LIMIT = 512
|
|
52
|
+
_gzip_cache = {}
|
|
53
|
+
_gzip_lock = threading.Lock()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def client_accepts_gzip(header_value):
|
|
57
|
+
"""Return True when an Accept-Encoding header permits gzip (excluding q=0)."""
|
|
58
|
+
if not header_value:
|
|
59
|
+
return False
|
|
60
|
+
for item in header_value.split(","):
|
|
61
|
+
parts = [part.strip() for part in item.split(";")]
|
|
62
|
+
if parts[0].lower() not in ("gzip", "x-gzip"):
|
|
63
|
+
continue
|
|
64
|
+
for param in parts[1:]:
|
|
65
|
+
if param.lower().startswith("q="):
|
|
66
|
+
try:
|
|
67
|
+
if float(param[2:]) <= 0:
|
|
68
|
+
return False
|
|
69
|
+
except ValueError:
|
|
70
|
+
pass
|
|
71
|
+
return True
|
|
72
|
+
return False
|
|
5
73
|
|
|
6
74
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
75
|
+
def is_compressible_file(file_path):
|
|
76
|
+
name = os.path.basename(file_path)
|
|
77
|
+
return os.path.splitext(name)[1].lower() in GZIP_EXTENSIONS or name == "LICENSE"
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def stamped(page):
|
|
81
|
+
for name in UNSTAMPED:
|
|
82
|
+
page = page.replace(name, name[:-1] + b"?v=" + STAMP + b'"')
|
|
83
|
+
return page
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def gzip_bytes_for(file_path, stat_result):
|
|
87
|
+
key = (file_path, stat_result.st_mtime_ns, stat_result.st_size)
|
|
88
|
+
with _gzip_lock:
|
|
89
|
+
cached = _gzip_cache.get(key)
|
|
90
|
+
if cached is not None:
|
|
91
|
+
return cached
|
|
92
|
+
content = Path(file_path).read_bytes()
|
|
93
|
+
if ENTRY and os.path.basename(file_path) == "index.html":
|
|
94
|
+
content = stamped(content)
|
|
95
|
+
compressed = gzip.compress(content, compresslevel=6)
|
|
96
|
+
with _gzip_lock:
|
|
97
|
+
if len(_gzip_cache) >= GZIP_CACHE_LIMIT:
|
|
98
|
+
_gzip_cache.clear()
|
|
99
|
+
_gzip_cache[key] = compressed
|
|
100
|
+
return compressed
|
|
10
101
|
|
|
11
102
|
|
|
12
103
|
class Handler(SimpleHTTPRequestHandler):
|
|
13
|
-
protocol_version = "HTTP/1.1"
|
|
104
|
+
protocol_version = "HTTP/1.1" # connections are kept and reused: a page asks for about a hundred script parts at once
|
|
105
|
+
|
|
106
|
+
def end_headers(self):
|
|
107
|
+
# Every file is checked afresh on each load: a build replaces its scripts while the browser may still hold an old
|
|
108
|
+
# entry script, which would ask for parts the new build no longer has and leave the page at its loading screen.
|
|
109
|
+
self.send_header("Cache-Control", "no-store" if ENTRY else "no-cache")
|
|
110
|
+
super().end_headers()
|
|
111
|
+
|
|
112
|
+
def redirect(self, location):
|
|
113
|
+
self.send_response(302)
|
|
114
|
+
self.send_header("Location", location)
|
|
115
|
+
self.send_header("Content-Length", "0")
|
|
116
|
+
self.end_headers()
|
|
117
|
+
|
|
118
|
+
def page_home(self, path):
|
|
119
|
+
"""The nearest folder at or above an address that holds an index.html, as an address ending in '/'."""
|
|
120
|
+
parts = path.strip("/").split("/")[:-1]
|
|
121
|
+
while parts:
|
|
122
|
+
home = "/" + "/".join(parts) + "/"
|
|
123
|
+
if os.path.isfile(os.path.join(self.translate_path(home), "index.html")):
|
|
124
|
+
return home
|
|
125
|
+
parts.pop()
|
|
126
|
+
return "/"
|
|
127
|
+
|
|
128
|
+
def _serve_request(self, send_body):
|
|
129
|
+
asked = urlsplit(self.path)
|
|
130
|
+
path = asked.path
|
|
131
|
+
last = path.rstrip("/").rsplit("/", 1)[-1]
|
|
132
|
+
if ENTRY and path in ("/", "/index.html") and asked.query != ENTRY:
|
|
133
|
+
self.redirect("/?" + ENTRY)
|
|
134
|
+
return
|
|
135
|
+
fs_path = self.translate_path(path)
|
|
136
|
+
if ROUTE_PARAM and last and "." not in last and not os.path.exists(fs_path):
|
|
137
|
+
home = self.page_home(path)
|
|
138
|
+
self.redirect(home + "?" + ROUTE_PARAM + "=" + quote(path[len(home) :].rstrip("/"), safe="/"))
|
|
139
|
+
return
|
|
140
|
+
|
|
141
|
+
target = fs_path
|
|
142
|
+
if os.path.isdir(target):
|
|
143
|
+
if not path.endswith("/"):
|
|
144
|
+
super().do_GET() if send_body else super().do_HEAD()
|
|
145
|
+
return
|
|
146
|
+
for index_name in ("index.html", "index.htm"):
|
|
147
|
+
candidate = os.path.join(target, index_name)
|
|
148
|
+
if os.path.isfile(candidate):
|
|
149
|
+
target = candidate
|
|
150
|
+
break
|
|
151
|
+
|
|
152
|
+
if (
|
|
153
|
+
os.path.isfile(target)
|
|
154
|
+
and "Range" not in self.headers
|
|
155
|
+
and is_compressible_file(target)
|
|
156
|
+
and client_accepts_gzip(self.headers.get("Accept-Encoding", ""))
|
|
157
|
+
):
|
|
158
|
+
try:
|
|
159
|
+
stat_result = os.stat(target)
|
|
160
|
+
payload = gzip_bytes_for(target, stat_result)
|
|
161
|
+
except OSError:
|
|
162
|
+
self.send_error(404, "File not found")
|
|
163
|
+
return
|
|
164
|
+
self.send_response(200)
|
|
165
|
+
self.send_header("Content-type", self.guess_type(target))
|
|
166
|
+
self.send_header("Content-Encoding", "gzip")
|
|
167
|
+
self.send_header("Vary", "Accept-Encoding")
|
|
168
|
+
self.send_header("Content-Length", str(len(payload)))
|
|
169
|
+
self.send_header("Last-Modified", self.date_time_string(stat_result.st_mtime))
|
|
170
|
+
self.end_headers()
|
|
171
|
+
if send_body:
|
|
172
|
+
self.wfile.write(payload)
|
|
173
|
+
return
|
|
174
|
+
|
|
175
|
+
super().do_GET() if send_body else super().do_HEAD()
|
|
176
|
+
|
|
177
|
+
def do_GET(self):
|
|
178
|
+
self._serve_request(send_body=True)
|
|
179
|
+
|
|
180
|
+
def do_HEAD(self):
|
|
181
|
+
self._serve_request(send_body=False)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
class Server(ThreadingHTTPServer):
|
|
185
|
+
# Connections waiting to be accepted: the default of 5 refused some of a page's parts when they were all asked for at
|
|
186
|
+
# once on a busy machine, and a page whose script part never arrives stays at its loading screen with no error.
|
|
187
|
+
request_queue_size = 256
|
|
188
|
+
daemon_threads = True
|
|
14
189
|
|
|
15
190
|
|
|
16
191
|
if __name__ == "__main__":
|
|
17
192
|
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8080
|
|
18
|
-
with
|
|
19
|
-
print(f"Serving Roamwright on port {server.server_port}", flush=True)
|
|
193
|
+
with Server(("127.0.0.1", port), Handler) as server:
|
|
20
194
|
root = f"http://127.0.0.1:{server.server_port}/"
|
|
21
|
-
print(f"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
195
|
+
print(f"Serving Roamwright on port {server.server_port}", flush=True)
|
|
196
|
+
if os.path.isfile("examples/index.html"):
|
|
197
|
+
print(f"All examples: {root}", flush=True)
|
|
198
|
+
print(f"A small world: {root}examples/small-world.html?seed=42", flush=True)
|
|
199
|
+
print(f"Alpine viaduct: {root}examples/viaduct.html?seed=42", flush=True)
|
|
200
|
+
print(f"Island: {root}examples/island.html?seed=42", flush=True)
|
|
25
201
|
try:
|
|
26
202
|
server.serve_forever()
|
|
27
203
|
except KeyboardInterrupt:
|
package/scripts/world.mk
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
# Consumer Makefiles set any world-specific variables (PORT, ROAMWRIGHT, CLEAN_PATHS) and include this file.
|
|
3
3
|
|
|
4
4
|
PORT ?= 8765
|
|
5
|
+
# The engine's scripts folder, wherever this file was included from (an installed package or an embedded engine worktree).
|
|
6
|
+
ROAMWRIGHT_SCRIPTS := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
|
|
5
7
|
PYTHON := $(if $(wildcard .venv/bin/python),.venv/bin/python,python3)
|
|
6
8
|
LOCAL_ROAMWRIGHT := $(if $(wildcard roamwright/package.json),$(CURDIR)/roamwright,)
|
|
7
9
|
ACTIVE_ROAMWRIGHT := $(if $(strip $(ROAMWRIGHT)),$(ROAMWRIGHT),$(LOCAL_ROAMWRIGHT))
|
|
@@ -39,7 +41,7 @@ deps: node_modules/.roamwright-installed .venv/.uv-synced
|
|
|
39
41
|
@git config core.hooksPath .githooks 2>/dev/null || true
|
|
40
42
|
|
|
41
43
|
dev-engine: deps-base
|
|
42
|
-
@ROAMWRIGHT="$(ACTIVE_ROAMWRIGHT)" $(PYTHON)
|
|
44
|
+
@ROAMWRIGHT="$(ACTIVE_ROAMWRIGHT)" $(PYTHON) $(ROAMWRIGHT_SCRIPTS)/dev-engine.py
|
|
43
45
|
|
|
44
46
|
check:
|
|
45
47
|
@sh scripts/check.sh
|