reorganize api doc

This commit is contained in:
2025-02-08 20:50:25 -06:00
parent 4361ad9daa
commit 95c64f51de
35 changed files with 513 additions and 305 deletions

View File

@@ -0,0 +1 @@
# packer

View File

@@ -0,0 +1,52 @@
# resources
## canonical(file)
## find_image(...args)
## find_sound(...args)
## find_script(...args)
## find_font(...args)
## getAllFiles(dir)
Return a list of recognized files in the given directory that are not matched by
.prosperonignore, skipping directories. Recognized extensions include scripts,
images, sounds, fonts, and libs.
**dir**: The directory to search.
**Returns**: An array of recognized file paths.
## gatherStats(filePaths)
Analyze a list of recognized files and categorize them by scripts, images, sounds,
fonts, libs, or other. Return a stats object with these counts and the total.
**filePaths**: An array of file paths to analyze.
**Returns**: { scripts, images, sounds, fonts, lib, other, total }
## pack(dir, outPath)
Create a ZIP archive of all recognized files (skipping those matched by .prosperonignore)
in the specified directory and write it to outPath. Recognized extensions are scripts,
images, sounds, fonts, or libs.
**dir**: The directory to zip.
**outPath**: The path (including filename) for the resulting ZIP file.
**Returns**: None
:raises Error: If the directory does not exist.

View File

@@ -1,11 +0,0 @@
# resources
## canonical(file)
## find_image(...args)
## find_sound(...args)
## find_script(...args)
## find_font(...args)

View File

@@ -1,4 +1,6 @@
# Preface: The Prosperon Manifesto
# Preface: The Prosperon Vision
![image](wizard.png)
Prosperon is based around a Javascript-like language, named "dull", engineered to be the quickest way to make computer games.
@@ -19,7 +21,6 @@ Uniformity is prioritized. Javascript allows for a powerful abstraction - the ob
!!! scholium
The object is the lingua franca of the API. For example, json.encode and json.decode converts objects to and from json strings; nota.encode and nota.decode converts objects to and from nota bytes, represented as a javascript arraybuffer. To convert a json string to a nota buffer, one would do:
```nota.encode(json.decode(str))```
4. **AI**
Prosperon is packed with tools to make it easy to work with AI. AI is an incredible productivity boost for programming, but it has a difficult time dealing with game engines like Unity and Unreal. Prosperon can, for example, generate an overview of your game, which you can plug into an AI for context so it will have an easy time helping with what you're stuck on.

BIN
docs/wizard.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

View File

@@ -1,54 +1,184 @@
Babel==2.15.0
beautifulsoup4==4.12.3
cairocffi==1.7.1
CairoSVG==2.7.1
certifi==2024.6.2
cffi==1.16.0
charset-normalizer==3.3.2
click==8.1.7
aiohappyeyeballs==2.4.4
aiohttp==3.11.11
aiohttp-cors==0.7.0
aiosignal==1.3.2
airportsdata==20241001
annotated-types==0.7.0
anyio==4.8.0
astor==0.8.1
attrs==25.1.0
babel==2.17.0
blake3==1.0.4
bracex==2.5.post1
cachetools==5.5.1
certifi==2024.12.14
charset-normalizer==3.4.1
click==8.1.8
cloudpickle==3.1.0
colorama==0.4.6
cssselect2==0.7.0
defusedxml==0.7.1
EditorConfig==0.12.4
coloredlogs==15.0.1
colorful==0.5.6
compressed-tensors==0.8.1
contourpy==1.3.1
cycler==0.12.1
dbus-python==1.3.2
depyf==0.18.0
dill==0.3.9
diskcache==5.6.3
distlib==0.3.9
distro==1.9.0
dnf==4.22.0
einops==0.8.0
Farama-Notifications==0.0.4
fastapi==0.115.7
filelock==3.16.1
flatbuffers==24.12.23
fonttools==4.55.3
frozenlist==1.5.0
fsspec==2024.12.0
gguf==0.10.0
ghp-import==2.1.0
gitdb==4.0.11
GitPython==3.1.42
idna==3.7
Jinja2==3.1.3
Markdown==3.5.2
MarkupSafe==2.1.5
mdsplit==0.4.2
gitdb==4.0.12
GitPython==3.1.44
google-api-core==2.24.0
google-auth==2.38.0
googleapis-common-protos==1.66.0
grpcio==1.70.0
gym==0.26.2
gym-notices==0.0.8
gymnasium==1.0.0
h11==0.14.0
httpcore==1.0.7
httptools==0.6.4
httpx==0.28.1
huggingface-hub==0.27.1
humanfriendly==10.0
idna==3.10
importlib_metadata==8.6.1
iniconfig==2.0.0
interegular==0.3.3
Jinja2==3.1.5
jiter==0.8.2
jsonschema==4.23.0
jsonschema-specifications==2024.10.1
kiwisolver==1.4.8
lark==1.2.2
libcomps==0.1.20
libdnf==0.73.4
lm-format-enforcer==0.10.9
Markdown==3.7
MarkupSafe==3.0.2
matplotlib==3.8.1
mergedeep==1.3.4
mkdocs==1.6.0
mkdocs-custommill==1.3.0
meson==1.4.1
mistral_common==1.5.2
mkdocs==1.6.1
mkdocs-awesome-pages-plugin==2.10.1
mkdocs-get-deps==0.2.0
mkdocs-git-revision-date-localized-plugin==1.2.6
mkdocs-git-revision-date-plugin==0.3.2
mkdocs-material==9.5.28
mkdocs-git-revision-date-localized-plugin==1.3.0
mkdocs-material==9.6.2
mkdocs-material-extensions==1.3.1
mkdocs-risonia-theme==0.1.12
mkdocs-terminal==4.4.0
mkdocs-windmill==1.0.5
mpmath==1.3.0
msgpack==1.1.0
msgspec==0.19.0
multidict==6.1.0
natsort==8.4.0
nest-asyncio==1.6.0
networkx==3.4.2
nftables==0.1
numpy==1.26.4
nvidia-cublas-cu12==12.4.5.8
nvidia-cuda-cupti-cu12==12.4.127
nvidia-cuda-nvrtc-cu12==12.4.127
nvidia-cuda-runtime-cu12==12.4.127
nvidia-cudnn-cu12==9.1.0.70
nvidia-cufft-cu12==11.2.1.3
nvidia-curand-cu12==10.3.5.147
nvidia-cusolver-cu12==11.6.1.9
nvidia-cusparse-cu12==12.3.1.170
nvidia-ml-py==12.570.86
nvidia-nccl-cu12==2.21.5
nvidia-nvjitlink-cu12==12.4.127
nvidia-nvtx-cu12==12.4.127
onnxruntime==1.20.1
openai==1.60.1
opencensus==0.11.4
opencensus-context==0.1.3
opencv-python-headless==4.11.0.86
outlines==0.1.11
outlines_core==0.1.26
packaging==23.2
paginate==0.5.6
paginate==0.5.7
pandas==2.1.2
partial-json-parser==0.2.1.1.post5
pathspec==0.12.1
pillow==10.4.0
platformdirs==4.2.0
pycparser==2.22
Pygments==2.17.2
pymdown-extensions==10.7
platformdirs==4.3.6
pluggy==1.5.0
prometheus-fastapi-instrumentator==7.0.2
prometheus_client==0.21.1
propcache==0.2.1
proto-plus==1.25.0
protobuf==5.29.2
psutil==6.1.1
py-cpuinfo==9.0.0
py-spy==0.4.0
pyasn1==0.6.1
pyasn1_modules==0.4.1
pybind11==2.13.6
pycountry==24.6.1
pydantic==2.10.6
pydantic_core==2.27.2
Pygments==2.19.1
PyGObject==3.48.2
pymdown-extensions==10.14.3
pyparsing==3.2.0
pytest==8.3.4
python-dateutil==2.8.2
pytz==2024.1
PyYAML==6.0.1
python-dotenv==1.0.1
pytz==2024.2
PyYAML==6.0.2
pyyaml_env_tag==0.1
regex==2023.12.25
pyzmq==26.2.0
ray==2.41.0
referencing==0.36.2
regex==2024.11.6
requests==2.32.3
rpds-py==0.22.3
rpm==4.19.1.1
rsa==4.9
safetensors==0.5.2
seaborn==0.13.2
sentencepiece==0.2.0
setuptools==75.8.0
six==1.16.0
smmap==5.0.1
soupsieve==2.5
termcolor==2.4.0
tinycss2==1.3.0
urllib3==2.2.1
watchdog==4.0.0
webencodings==0.5.1
smart-open==7.1.0
smmap==5.0.2
sniffio==1.3.1
stable_baselines3==2.4.0
starlette==0.45.3
sympy==1.13.1
systemd-python==235
tiktoken==0.7.0
tokenizers==0.21.0
torch==2.5.1
torchvision==0.20.1
tqdm==4.67.1
transformers==4.48.1
triton==3.1.0
typing_extensions==4.12.2
tzdata==2024.2
urllib3==2.3.0
uvicorn==0.34.0
uvloop==0.21.0
virtualenv==20.29.1
vllm==0.6.6.post1
watchdog==6.0.0
watchfiles==1.0.4
wcmatch==10.0
websockets==14.2
wrapt==1.17.2
xformers==0.0.28.post3
xgrammar==0.1.11
yarl==1.18.3
zipp==3.21.0

View File

@@ -1,9 +1,8 @@
// set up events on prosperon
prosperon.DOC = Symbol('+documentation+')
(function engine() {
prosperon.DOC = Symbol('+documentation+') // Symbol for documentation references
var listeners = new Map()
prosperon.on = function(type, callback)
{
prosperon.on = function(type, callback) {
if (!listeners.has(type)) listeners.set(type, [])
listeners.get(type).push(callback)
@@ -15,8 +14,7 @@ prosperon.on = function(type, callback)
}
}
prosperon.dispatch = function(type, data)
{
prosperon.dispatch = function(type, data) {
var arr = listeners.get(type)
if (!arr) return
for (var callback of arr) callback(data)
@@ -26,34 +24,33 @@ var os = use_embed('os')
var js = use_embed('js')
prosperon.on('SIGINT', function() {
os.exit();
os.exit()
})
prosperon.on('SIGABRT', function() {
console.error(new Error('SIGABRT'));
os.exit(1);
console.error(new Error('SIGABRT'))
os.exit(1)
})
prosperon.on('SIGSEGV', function() {
console.error(new Error('SIGSEGV'));
os.exit(1);
console.error(new Error('SIGSEGV'))
os.exit(1)
})
var use_cache = {}
Object.defineProperty(Function.prototype, "hashify", {
value: function () {
var hash = new Map();
var fn = this;
var hash = new Map()
var fn = this
function hashified(...args) {
var key = args[0];
if (!hash.has(key)) hash.set(key, fn(...args));
return hash.get(key);
var key = args[0]
if (!hash.has(key)) hash.set(key, fn(...args))
return hash.get(key)
}
return hashified;
return hashified
},
});
})
var io = use_embed('io')
var tracy = use_embed('tracy')
@@ -62,7 +59,7 @@ var RESPATH = 'scripts/modules/resources.js'
var canonical = io.realdir(RESPATH) + 'resources.js'
var content = io.slurp(RESPATH)
var resources = js.eval(RESPATH, `(function setup_resources(){${content}})`).call({})
console.print(resources.canonical('resources.js'))
use_cache[resources.canonical('resources.js')] = resources
function print_api(obj) {
@@ -86,41 +83,39 @@ prosperon.PATH = [
// path is the path of a module or script to resolve
var script_fn = function script_fn(path) {
var parsed = {}
var file = resources.find_script(path);
var file = resources.find_script(path)
if (!file) {
// attempt to bare load
parsed.module_ret = bare_load(path);
parsed.module_ret = bare_load(path)
if (!parsed.module_ret) throw new Error(`Module ${path} could not be created`)
return parsed
}
var content = io.slurp(file)
var parsed = parse_file(content);
var module_name = file.name();
var content = io.slurp(file)
var parsed = parse_file(content)
var module_name = file.name()
parsed.module_ret = bare_load(path)
parsed.module_ret ??= {}
if (parsed.module) {
var mod_script = `(function setup_${module_name}_module(){ var self = this; var $ = this; var exports = {}; var module = {exports: exports}; var define = undefined; ${parsed.module}})`;
var module_fn = js.eval(file, mod_script);
parsed.module_ret = module_fn.call(parsed.module_ret);
var mod_script = `(function setup_${module_name}_module(){ var self = this; var $ = this; var exports = {}; var module = {exports: exports}; var define = undefined; ${parsed.module}})`
var module_fn = js.eval(file, mod_script)
parsed.module_ret = module_fn.call(parsed.module_ret)
if (parsed.module_ret === undefined || parsed.module_ret === null)
throw new Error(`Module ${module_name} must return a value`);
parsed.module_fn = module_fn;
throw new Error(`Module ${module_name} must return a value`)
parsed.module_fn = module_fn
// console.log(`api for ${path}`)
// print_api(parsed.module_ret)
}
if (parsed.program) {
var prog_script = `(function use_${module_name}() { var self = this; var $ = this.__proto__; ${parsed.program}})`;
parsed.prog_fn = js.eval(file, prog_script);
var prog_script = `(function use_${module_name}() { var self = this; var $ = this.__proto__; ${parsed.program}})`
parsed.prog_fn = js.eval(file, prog_script)
}
return parsed;
}.hashify();
return parsed
}.hashify()
function bare_load(file) {
try {
@@ -132,91 +127,88 @@ function bare_load(file) {
return undefined
}
var res_cache = {};
var res_cache = {}
function console_rec(category, priority, line, file, msg)
{
return `${file}:${line}: [${category} ${priority}]: ${msg}` + "\n";
function console_rec(category, priority, line, file, msg) {
return `${file}:${line}: [${category} ${priority}]: ${msg}\n`
}
var logfile = io.open('.prosperon/log.txt')
function pprint(msg, lvl = 0) {
if (!logfile) return;
if (!logfile) return
if (typeof msg === "object") msg = JSON.stringify(msg, null, 2);
if (typeof msg === "object") msg = JSON.stringify(msg, null, 2)
var file = "nofile";
var line = 0;
var file = "nofile"
var line = 0
var caller = new Error().stack.split("\n")[2];
var caller = new Error().stack.split("\n")[2]
if (caller) {
var md = caller.match(/\((.*)\:/);
var m = md ? md[1] : "SCRIPT";
if (m) file = m;
md = caller.match(/\:(\d*)\)/);
m = md ? md[1] : 0;
if (m) line = m;
var md = caller.match(/\((.*)\:/)
var m = md ? md[1] : "SCRIPT"
if (m) file = m
md = caller.match(/\:(\d*)\)/)
m = md ? md[1] : 0
if (m) line = m
}
var fmt = console_rec("script", lvl, line,file, msg);
var fmt = console_rec("script", lvl, line, file, msg)
console.print(fmt)
if (logfile)
logfile.write(fmt)
if (tracy) tracy.message(fmt);
};
console.spam = function spam(msg) {
pprint(msg, 0);
};
console.debug = function debug(msg) {
pprint(msg, 1);
};
console.info = function info(msg) {
pprint(msg, 2);
};
console.warn = function warn(msg) {
pprint(msg, 3);
};
console.log = function(msg)
{
pprint(msg, 2)
if (tracy) tracy.message(fmt)
}
console.spam = function(msg) {
pprint(msg, 0)
}
console.debug = function(msg) {
pprint(msg, 1)
}
console.info = function(msg) {
pprint(msg, 2)
}
console.warn = function(msg) {
pprint(msg, 3)
}
console.log = function(msg) {
pprint(msg, 2)
}
console.error = function(e) {
if (!e)
e = new Error();
if (!e) e = new Error()
pprint(`${e.name} : ${e.message}
${e.stack}`, 4)
};
}
console.panic = function(e) {
pprint(e, 5)
os.quit()
}
console.assert = function(op, str = `assertion failed [value '${op}']`) {
if (!op) console.panic(str)
}
console.panic = function (e) {
pprint(e , 5)
os.quit();
};
os.on('uncaught_exception', function(e) { console.error(e) })
console.assert = function (op, str = `assertion failed [value '${op}']`) {
if (!op) console.panic(str);
};
os.on('uncaught_exception', function(e) { console.error(e); });
console.doc = {
log: "Output directly to in game console.",
level: "Set level to output logging to console.",
info: "Output info level message.",
warn: "Output warn level message.",
error: "Output error level message, and print stacktrace.",
critical: "Output critical level message, and exit game immediately.",
write: "Write raw text to console.",
say: "Write raw text to console, plus a newline.",
stack: "Output a stacktrace to console.",
clear: "Clear console.",
};
console[prosperon.DOC] = {
doc: "The console object provides various logging, debugging, and output methods.",
spam: "Output a spam-level message for very verbose logging.",
debug: "Output a debug-level message.",
info: "Output info level message.",
warn: "Output warn level message.",
error: "Output error level message, and print stacktrace.",
panic: "Output a panic-level message and exit the program.",
assert: "If the condition is false, print an error and panic.",
critical: "Output critical level message, and exit game immediately.",
write: "Write raw text to console.",
say: "Write raw text to console, plus a newline.",
log: "Output directly to in game console.",
level: "Set level to output logging to console.",
stack: "Output a stacktrace to console.",
clear: "Clear console."
}
var BASEPATH = 'scripts/core/base.js'
var script = io.slurp(BASEPATH)
@@ -224,36 +216,31 @@ var fnname = "base"
script = `(function ${fnname}() { ${script}; })`
js.eval(BASEPATH, script)()
function add_timer(obj, fn, seconds)
{
function add_timer(obj, fn, seconds) {
var timers = obj[TIMERS]
var stop = function () {
if (!timer) return
timers.delete(stop);
timer.fn = undefined;
timer = undefined;
};
function execute() {
if (fn)
timer.remain = fn(stop.seconds);
if (!timer) return
if (!timer.remain)
stop();
else
stop.seconds = timer.remain;
timers.delete(stop)
timer.fn = undefined
timer = undefined
}
var timer = os.make_timer(execute);
timer.remain = seconds;
function execute() {
if (fn) timer.remain = fn(stop.seconds)
if (!timer) return
if (!timer.remain) stop()
else stop.seconds = timer.remain
}
stop.remain = seconds;
stop.seconds = seconds;
var timer = os.make_timer(execute)
timer.remain = seconds
stop.remain = seconds
stop.seconds = seconds
timers.push(stop);
return stop;
timers.push(stop)
return stop
}
var DEAD = Symbol()
@@ -264,28 +251,27 @@ var REGGIES = Symbol()
var UNDERLINGS = Symbol()
var OVERLING = Symbol()
var actor = {};
globalThis.actor = {}
var so_ext;
var so_ext
switch(os.platform()) {
case 'Windows':
so_ext = '.dll';
break;
so_ext = '.dll'
break
default:
so_ext = '.so';
break;
so_ext = '.so'
break
}
var use = function use(file) {
if (use_cache[file]) return use_cache[file];
globalThis.use = function use(file) {
if (use_cache[file]) return use_cache[file]
var mod = script_fn(file)
use_cache[file] = mod.module_ret
return use_cache[file]
}
use[prosperon.DOC] = 'Return the value from the provided path to a module'.
globalThis.json = use('json')
function parse_file(content) {
@@ -301,7 +287,7 @@ function parse_file(content) {
if (!module.match(/return\s+[^;]+;?\s*$/))
throw new Error("Module section must end with a return statement")
var pad = '\n'.repeat(module.split('\n').length+2) // add 2 from the split search
var pad = '\n'.repeat(module.split('\n').length+2)
return {
module,
program: pad+parts[1]
@@ -309,119 +295,106 @@ function parse_file(content) {
}
//////////////////
///////REGISTRANT
// REGISTRANT
/////////////////
/*
Factory for creating registries. Register one with 'X.register',
which returns a function that, when invoked, cancels the registry.
*/
var Register = {
registries: [],
add_cb(name) {
var n = {};
var fns = [];
var n = {}
var fns = []
n.register = function (fn, oname) {
if (typeof fn !== 'function') return;
if (typeof fn !== 'function') return
var dofn = function (...args) {
fn(...args);
};
Object.defineProperty(dofn, 'name', {value:`do_${oname}`});
fn(...args)
}
Object.defineProperty(dofn, 'name', {value:`do_${oname}`})
var left = 0;
var right = fns.length - 1;
dofn.layer = fn.layer;
dofn.layer ??= 0;
var left = 0
var right = fns.length - 1
dofn.layer = fn.layer
dofn.layer ??= 0
while (left <= right) {
var mid = Math.floor((left + right) / 2);
var mid = Math.floor((left + right) / 2)
if (fns[mid] === dofn.layer) {
left = mid;
break;
} else if (fns[mid].layer < dofn.layer) left = mid + 1;
else right = mid - 1;
left = mid
break
} else if (fns[mid].layer < dofn.layer) left = mid + 1
else right = mid - 1
}
fns.splice(left, 0, dofn);
fns.splice(left, 0, dofn)
return function () {
fns.delete(dofn)
};
};
}
}
prosperon[name] = function (...args) {
// tracy.fiber_enter(vector.fib);
fns.forEach(fn => {
fn(...args)
});
// tracy.fiber_leave(vector.fib);
};
})
}
Object.defineProperty(prosperon[name], 'name', {value:name})
prosperon[name].fns = fns
Object.defineProperty(prosperon[name], 'name', {value:name});
prosperon[name].fns = fns;
n.clear = function () {
fns = [];
};
fns = []
}
Register[name] = n;
Register.registries[name] = n;
return n;
Register[name] = n
Register.registries[name] = n
return n
},
};
Register.pull_registers = function pull_registers(obj)
{
var reggies = [];
for (var reg in Register.registries) {
if (typeof obj[reg] === "function")
reggies.push(reg);
}
return reggies;
}
Register.register_obj = function register_obj(obj, reg)
{
var fn = obj[reg].bind(obj);
fn.layer = obj[reg].layer;
var name = obj.ur ? obj.ur.name : obj.toString();
obj[TIMERS].push(Register.registries[reg].register(fn, name));
if (!obj[reg].name) Object.defineProperty(obj[reg], 'name', {value:`${obj._file}_${reg}`});
Register.pull_registers = function pull_registers(obj) {
var reggies = []
for (var reg in Register.registries) {
if (typeof obj[reg] === "function")
reggies.push(reg)
}
return reggies
}
Register.register_obj = function register_obj(obj, reg) {
var fn = obj[reg].bind(obj)
fn.layer = obj[reg].layer
var name = obj.ur ? obj.ur.name : obj.toString()
obj[TIMERS].push(Register.registries[reg].register(fn, name))
if (!obj[reg].name) Object.defineProperty(obj[reg], 'name', {value:`${obj._file}_${reg}`})
}
Register.check_registers = function check_registers(obj) {
if (obj[REGGIES]) {
if (obj[REGGIES].length == 0) return;
// fast path
if (obj[REGGIES].length == 0) return
for (var reg of obj[REGGIES])
Register.register_obj(obj,reg);
return;
Register.register_obj(obj,reg)
return
}
for (var reg in Register.registries) {
if (typeof obj[reg] === "function")
Register.register_obj(obj,reg);
Register.register_obj(obj,reg)
}
};
}
Register.add_cb("appupdate");
Register.add_cb("update").doc = "Called once per frame.";
Register.add_cb("physupdate");
Register.add_cb("gui");
Register.add_cb("hud");
Register.add_cb("draw");
Register.add_cb("imgui");
Register.add_cb("app");
Register.add_cb("appupdate")
Register.add_cb("update").doc = "Called once per frame."
Register.add_cb("physupdate")
Register.add_cb("gui")
Register.add_cb("hud")
Register.add_cb("draw")
Register.add_cb("imgui")
Register.add_cb("app")
function cant_kill()
{
throw Error("Can't kill an object in its spawning code. Move the kill command to awake.");
function cant_kill() {
throw Error("Can't kill an object in its spawning code. Move the kill command to awake.")
}
actor.toString = function() { return this[FILE] }
actor.spawn = function spawn(script, config, callback) {
if (this[DEAD]) throw Error("Attempting to spawn on a dead actor")
var prog
@@ -430,14 +403,14 @@ actor.spawn = function spawn(script, config, callback) {
prog.module_ret = {}
prog.prog_fn = function() {}
} else {
prog = script_fn(script);
prog = script_fn(script)
if (!prog.prog_fn) throw new Error(`Script ${script} is not an actor script or has no actor component`)
}
var underling;
prog.module_ret.__proto__ = actor;
underling = Object.create(prog.module_ret);
underling[OVERLING] = this;
var underling
prog.module_ret.__proto__ = actor
underling = Object.create(prog.module_ret)
underling[OVERLING] = this
underling[FILE] = script
underling[TIMERS] = []
underling[UNDERLINGS] = new Set()
@@ -475,37 +448,32 @@ actor.spawn = function spawn(script, config, callback) {
configurable:false
})
if (callback) callback(underling, {
message:"created"
})
if (callback) callback(underling, { message:"created" })
try{
prog.prog_fn.call(underling)
} catch(e) {throw e}
if (underling[DEAD])
return undefined
try {
prog.prog_fn.call(underling)
} catch(e) { throw e }
if (underling[DEAD]) return undefined
if (typeof config === 'object') Object.assign(underling, config)
if (typeof config === 'object') Object.assign(underling,config);
if (!underling[REGGIES])
underling.__proto__[REGGIES] = Register.pull_registers(underling)
underling.__proto__[REGGIES] = Register.pull_registers(underling)
Register.check_registers(underling);
Register.check_registers(underling)
if (underling.awake) underling.awake()
if (underling.awake) underling.awake();
this[UNDERLINGS].add(underling);
if (underling.tag)
act.tag_add(underling.tag, underling)
this[UNDERLINGS].add(underling)
if (underling.tag) act.tag_add(underling.tag, underling)
underling[GARBAGE] = underling.garbage
return underling;
};
return underling
}
actor.clear = function actor_clear()
{
actor.clear = function actor_clear() {
this[UNDERLINGS].forEach(p => {
p.kill();
p.kill()
})
this[UNDERLINGS].clear()
}
@@ -515,29 +483,94 @@ var input = use('input')
actor.kill = function kill() {
if (this[DEAD]) return
this[DEAD] = true
this[TIMERS].slice().forEach(t => t()) // slice in case something is removed from timers while running
this[TIMERS].slice().forEach(t => t())
delete this[TIMERS]
input.do_uncontrol(this);
input.do_uncontrol(this)
this.clear()
this[OVERLING][UNDERLINGS].delete(this)
delete this[UNDERLINGS]
if (typeof this.garbage === "function") this.garbage();
if (typeof this.then === "function") this.then();
if (typeof this.garbage === "function") this.garbage()
if (typeof this.then === "function") this.then()
act.tag_clear_guid(this)
};
}
actor.kill.doc = `Remove this actor and all its underlings from existence.`
actor.kill.doc = `Remove this actor and all its underlings from existence.`;
actor.delay = function (fn, seconds) { add_timer(this, fn, seconds) }
actor.delay.doc = `Call 'fn' after 'seconds' with 'this' set to the actor.`;
actor.delay = function(fn, seconds) {
add_timer(this, fn, seconds)
}
actor.delay.doc = `Call 'fn' after 'seconds' with 'this' set to the actor.`
var act = use('actor')
actor[UNDERLINGS] = new Set()
globalThis.mixin("color");
globalThis.mixin("color")
use('cmd')(prosperon.argv)
// ---------------------------------------------------------------------------
// Documentation blocks following the style shown in time.js
// ---------------------------------------------------------------------------
// Document the main prosperon object
prosperon[prosperon.DOC] = {
doc: `The main prosperon object providing event dispatch, signal handling, and engine management.`,
DOC: `Symbol used to store documentation references on objects.`,
on: `Register a callback function for a given event type. Returns a function to remove the callback.`,
dispatch: `Dispatch an event of the given type, calling all registered callbacks with the provided data.`,
PATH: `Array of directory paths that Prosperon will search to find scripts or modules.`
}
// Document the actor object/prototype
actor[prosperon.DOC] = {
doc: `The actor object/prototype, serving as a base for all game actors or entities.`,
spawn: `Create a new actor from a script, optionally applying a config object, then call the new actor's 'awake' method.`,
kill: `Destroy this actor, removing it from the game along with all underlings. Frees resources and triggers garbage if defined.`,
clear: `Remove all child (underling) actors by calling kill on each.`,
delay: `Schedule a function to be called after a specified delay (in seconds) on this actor.`,
toString: `Return the script filename associated with this actor instance.`
}
// Expand console.doc to document the console object and missing methods
console.doc.doc = `The console object provides various logging, debugging, and output methods.`
console.doc.spam = `Output a spam-level message for very verbose logging.`
console.doc.debug = `Output a debug-level message.`
console.doc.panic = `Output a panic-level message and exit the program.`
console.doc.assert = `If the condition is false, print an error and panic.`
// Document the Register object
Register[prosperon.DOC] = {
doc: `Factory for creating and managing event registries (e.g. update, draw, etc.) within Prosperon.`,
add_cb: `Create or retrieve a registry for an event type, exposing a 'register' method for callbacks.`,
pull_registers: `Gather the names of all recognized event methods implemented by an object.`,
register_obj: `Bind an object's event method to the relevant registry. The unregistration handle goes in the actor's timers.`,
check_registers: `Automatically register recognized events (like 'update', 'gui', etc.) on an object.`,
}
// Document some engine-internal symbols and utility functions
var engineDoc = {
doc: `Misc. internal references and symbols used by Prosperon engine for actor lifecycle and script handling.`,
DEAD: `Symbol marking an actor as dead.`,
GARBAGE: `Symbol referencing an actor's optional garbage callback.`,
FILE: `Symbol storing the script filename for this actor.`,
TIMERS: `Symbol storing an array of active delayed calls (timers) on an actor.`,
REGGIES: `Symbol referencing the event registry list for an actor.`,
UNDERLINGS: `Symbol referencing a Set of child actors spawned by this actor.`,
OVERLING: `Symbol referencing this actor's parent (the actor that spawned it).`,
use: `Load or retrieve a module from cache, from either an embedded or dynamic library (.so/.dll).`,
script_fn: `Parse a script and return compiled module/program sections (if any).`,
bare_load: `Attempt to load a module either from embed or a native library. Returns the loaded module or undefined.`,
parse_file: `Split a script file content into module and program sections. Module must end with a 'return' statement.`,
print_api: `Debug utility that prints the properties (API) of an object.`,
pprint: `Internal printing helper that formats logs and sends them to console, file, and Tracy if present.`,
res_cache: `Cache object that may store loaded resources (scripts, data, etc.).`,
use_cache: `Cache object that stores previously loaded modules/scripts.`,
json: `Reference to the JSON module used globally for parse/stringify.`,
mixin_color: `Inject color-related mixin methods into globalThis.`,
so_ext: `Platform-specific extension for dynamic libraries ('.so' on Unix-like, '.dll' on Windows).`
}
prosperon.engineDoc = engineDoc
})()

View File

@@ -87,6 +87,9 @@ Cmdline.register_order(
else
app = actor.spawn("nogame.js");
// rm actor so it can't be tampered
globalThis.actor = undefined
var ren = use('render')
while(1) loop.step();

View File

@@ -120,7 +120,7 @@ function writeDocsForObject(obj, lines, level, name) {
var docs = io.enumerate("scripts/modules", 0)
docs = docs.filter(x => io.match("**/*.js", x)).map(x => x.name())
var APIPATH = '.src/docs/api/'
var APIPATH = '.src/docs/api/modules'
ret.print_api = function(obj) {
// Old console-based printing. We'll leave as-is or minimal changes if desired.
@@ -154,7 +154,6 @@ ret.print_modules = function() {
}
}
// Writes each module's docs to .src/docs/api/<moduleName>.md
ret.write_modules = function() {
// rm all in APIPATH
var old = io.enumerate(APIPATH, 0)
@@ -180,7 +179,7 @@ ret.write_modules = function() {
}
ret.write_c_types = function() {
var CTYPEPATH = '.src/docs/api/c_types'
var CTYPEPATH = '.src/docs/api/types'
// Remove old ctype docs except index.md
var old = io.enumerate(CTYPEPATH, 0)

View File

@@ -3,7 +3,7 @@ var render = {}
var io = use('io')
var os = use('os')
var controller = use('controller')
var tracy = use('tracy')
var graphics = use('graphics')
var config = use('config.js')
@@ -815,7 +815,7 @@ std_sampler = render._main.make_sampler({
render._main.present = gpupresent;
tracy.gpu_init()
if (tracy) tracy.gpu_init()
render.queue = function(cmd) {
if (Array.isArray(cmd))
@@ -850,4 +850,4 @@ render.setup_hud[prosperon.DOC] = `Switch the current queue to the HUD render qu
:return: None
`
return render
return render

View File

@@ -1,6 +1,6 @@
var io = use('io')
var miniz = use('miniz')
var os = use('os')
var io = use_embed('io')
var miniz = use_embed('miniz')
var os = use_embed('os')
// Merge of the old resources.js and packer.js functionalities
var Resources = {}