remove some docstrings to save per actor memory
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
var input = use('input')
|
var input = use('input')
|
||||||
var util = use('util')
|
|
||||||
|
|
||||||
var downkeys = {};
|
var downkeys = {};
|
||||||
|
|
||||||
|
|||||||
@@ -100,8 +100,6 @@ var graphics
|
|||||||
|
|
||||||
var gameactor
|
var gameactor
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var last = os.now()
|
var last = os.now()
|
||||||
|
|
||||||
// FPS tracking
|
// FPS tracking
|
||||||
|
|||||||
1266
scripts/base.cm
1266
scripts/base.cm
File diff suppressed because it is too large
Load Diff
@@ -15,7 +15,6 @@ log.console("Cleaning build artifacts...")
|
|||||||
// Remove the build directory
|
// Remove the build directory
|
||||||
try {
|
try {
|
||||||
io.rmdir('.cell/build')
|
io.rmdir('.cell/build')
|
||||||
remove_dir('.cell/build')
|
|
||||||
log.console("Build directory removed")
|
log.console("Build directory removed")
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.error("Failed during cleanup: " + e)
|
log.error("Failed during cleanup: " + e)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
(function engine() {
|
(function engine() {
|
||||||
globalThis.cell = prosperon
|
globalThis.cell = prosperon
|
||||||
cell.DOC = cell.hidden.DOCSYM
|
cell.DOC = Symbol()
|
||||||
var ACTORDATA = cell.hidden.ACTORSYM
|
var ACTORDATA = cell.hidden.ACTORSYM
|
||||||
ACTORDATA = '__ACTORDATA__' // TODO: implement the actual actorsym
|
ACTORDATA = '__ACTORDATA__' // TODO: implement the actual actorsym
|
||||||
var SYSYM = '__SYSTEM__'
|
var SYSYM = '__SYSTEM__'
|
||||||
@@ -103,6 +103,7 @@ function disrupt(err)
|
|||||||
os.on(disrupt)
|
os.on(disrupt)
|
||||||
|
|
||||||
var js = use_embed('js')
|
var js = use_embed('js')
|
||||||
|
|
||||||
var io = use_embed('io')
|
var io = use_embed('io')
|
||||||
|
|
||||||
if (!io.exists('.cell')) {
|
if (!io.exists('.cell')) {
|
||||||
@@ -236,6 +237,9 @@ globalThis.use = function use(file, ...args) {
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
globalThis.json = use('json')
|
||||||
|
var time = use('time')
|
||||||
|
var st_now = time.number()
|
||||||
|
|
||||||
var shop = use('shop')
|
var shop = use('shop')
|
||||||
var config = shop.load_config()
|
var config = shop.load_config()
|
||||||
@@ -252,9 +256,7 @@ config.system.__proto__ = default_config
|
|||||||
ENETSERVICE = config.system.net_service
|
ENETSERVICE = config.system.net_service
|
||||||
REPLYTIMEOUT = config.system.reply_timeout
|
REPLYTIMEOUT = config.system.reply_timeout
|
||||||
|
|
||||||
globalThis.json = use('json')
|
|
||||||
globalThis.text = use('text')
|
globalThis.text = use('text')
|
||||||
var time = use('time')
|
|
||||||
|
|
||||||
// Load actor-specific configuration
|
// Load actor-specific configuration
|
||||||
function load_actor_config(program) {
|
function load_actor_config(program) {
|
||||||
@@ -333,7 +335,6 @@ stone.p = function(object)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var util = use('util')
|
var util = use('util')
|
||||||
var math = use('math')
|
|
||||||
var crypto = use('crypto')
|
var crypto = use('crypto')
|
||||||
|
|
||||||
var HEADER = Symbol()
|
var HEADER = Symbol()
|
||||||
@@ -647,8 +648,6 @@ function turn(msg)
|
|||||||
|
|
||||||
load_actor_config(cell.args.program)
|
load_actor_config(cell.args.program)
|
||||||
|
|
||||||
log.console(`actor ${cell.args.program} is ${cell.args.main}`)
|
|
||||||
|
|
||||||
actor_mod.register_actor(cell.id, turn, cell.args.main, config.system.ar_timer)
|
actor_mod.register_actor(cell.id, turn, cell.args.main, config.system.ar_timer)
|
||||||
|
|
||||||
if (config.system.actor_memory)
|
if (config.system.actor_memory)
|
||||||
@@ -773,9 +772,6 @@ function enet_check()
|
|||||||
// Finally, run the program
|
// Finally, run the program
|
||||||
actor_mod.setname(cell.args.program)
|
actor_mod.setname(cell.args.program)
|
||||||
|
|
||||||
// Load actor-specific configuration before running
|
|
||||||
|
|
||||||
|
|
||||||
var prog = null
|
var prog = null
|
||||||
var progPath = cell.args.program
|
var progPath = cell.args.program
|
||||||
|
|
||||||
@@ -791,7 +787,6 @@ if (io.exists(progPath + ACTOR_EXT) && !io.is_directory(progPath + ACTOR_EXT)) {
|
|||||||
if (!prog)
|
if (!prog)
|
||||||
throw new Error(cell.args.program + " not found.");
|
throw new Error(cell.args.program + " not found.");
|
||||||
|
|
||||||
|
|
||||||
var progDir = io.realdir(prog) + "/" + prog.substring(0, prog.lastIndexOf('/'))
|
var progDir = io.realdir(prog) + "/" + prog.substring(0, prog.lastIndexOf('/'))
|
||||||
|
|
||||||
io.mount(progDir.replace(/\/+$/, ''))
|
io.mount(progDir.replace(/\/+$/, ''))
|
||||||
|
|||||||
@@ -521,13 +521,4 @@ function format_number(num, format) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------- documentation -------------------------------------------- */
|
|
||||||
|
|
||||||
text[cell.DOC] = {
|
|
||||||
doc: "Text conversion and formatting utilities",
|
|
||||||
text: "text(value, ...) → formatted text string"
|
|
||||||
};
|
|
||||||
|
|
||||||
/* -------- exports -------------------------------------------------- */
|
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
@@ -1,20 +1,6 @@
|
|||||||
var util = this
|
var util = this
|
||||||
util[cell.DOC] = `
|
|
||||||
A collection of general-purpose utility functions for object manipulation, merging,
|
|
||||||
deep copying, safe property access, etc.
|
|
||||||
`
|
|
||||||
|
|
||||||
util.deepfreeze = function (obj) {
|
return util
|
||||||
for (var key in obj) {
|
|
||||||
if (typeof obj[key] === "object") Object.deepfreeze(obj[key])
|
|
||||||
}
|
|
||||||
Object.freeze(obj)
|
|
||||||
}
|
|
||||||
util.deepfreeze[cell.DOC] = `
|
|
||||||
:param obj: The object to recursively freeze.
|
|
||||||
:return: None
|
|
||||||
Recursively freeze an object and all of its nested objects so they cannot be modified.
|
|
||||||
`
|
|
||||||
|
|
||||||
util.dainty_assign = function (target, source) {
|
util.dainty_assign = function (target, source) {
|
||||||
Object.keys(source).forEach(function (k) {
|
Object.keys(source).forEach(function (k) {
|
||||||
@@ -25,13 +11,6 @@ util.dainty_assign = function (target, source) {
|
|||||||
else target[k] = source[k]
|
else target[k] = source[k]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
util.dainty_assign[cell.DOC] = `
|
|
||||||
:param target: The target object whose keys may be updated.
|
|
||||||
:param source: The source object containing new values.
|
|
||||||
:return: None
|
|
||||||
Copy non-function properties from source into matching keys of target without overwriting
|
|
||||||
keys that don't exist in target. Arrays are deep-copied, and objects are recursively assigned.
|
|
||||||
`
|
|
||||||
|
|
||||||
util.get = function (obj, path, defValue) {
|
util.get = function (obj, path, defValue) {
|
||||||
if (!path) return undefined
|
if (!path) return undefined
|
||||||
@@ -39,23 +18,10 @@ util.get = function (obj, path, defValue) {
|
|||||||
var result = pathArray.reduce((prevObj, key) => prevObj && prevObj[key], obj)
|
var result = pathArray.reduce((prevObj, key) => prevObj && prevObj[key], obj)
|
||||||
return result === undefined ? defValue : result
|
return result === undefined ? defValue : result
|
||||||
}
|
}
|
||||||
util.get[cell.DOC] = `
|
|
||||||
:param obj: The object to traverse.
|
|
||||||
:param path: A string like "a.b.c" or an array of path segments.
|
|
||||||
:param defValue: The default value if the property is undefined.
|
|
||||||
:return: The nested property or defValue.
|
|
||||||
Safely retrieve a nested property from obj at path (array or dot-string).
|
|
||||||
Returns defValue if the property is undefined.
|
|
||||||
`
|
|
||||||
|
|
||||||
util.isEmpty = function(o) {
|
util.isEmpty = function(o) {
|
||||||
return Object.keys(o).length === 0
|
return Object.keys(o).length === 0
|
||||||
}
|
}
|
||||||
util.isEmpty[cell.DOC] = `
|
|
||||||
:param o: The object to check.
|
|
||||||
:return: Boolean indicating if the object is empty.
|
|
||||||
Return true if the object has no own properties, otherwise false.
|
|
||||||
`
|
|
||||||
|
|
||||||
util.dig = function (obj, path, def = {}) {
|
util.dig = function (obj, path, def = {}) {
|
||||||
var pp = path.split(".")
|
var pp = path.split(".")
|
||||||
@@ -65,14 +31,6 @@ util.dig = function (obj, path, def = {}) {
|
|||||||
obj[pp[pp.length - 1]] = def
|
obj[pp[pp.length - 1]] = def
|
||||||
return def
|
return def
|
||||||
}
|
}
|
||||||
util.dig[cell.DOC] = `
|
|
||||||
:param obj: The root object to modify.
|
|
||||||
:param path: A dot-string specifying nested objects to create.
|
|
||||||
:param def: The value to store in the final path component, default {}.
|
|
||||||
:return: The assigned final value.
|
|
||||||
Ensure a nested path of objects exists inside obj; create objects if missing, and set
|
|
||||||
the final path component to def.
|
|
||||||
`
|
|
||||||
|
|
||||||
util.access = function (obj, name) {
|
util.access = function (obj, name) {
|
||||||
var dig = name.split(".")
|
var dig = name.split(".")
|
||||||
@@ -82,13 +40,6 @@ util.access = function (obj, name) {
|
|||||||
}
|
}
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
util.access[cell.DOC] = `
|
|
||||||
:param obj: The object to traverse.
|
|
||||||
:param name: A dot-string path (e.g. "foo.bar.baz").
|
|
||||||
:return: The value at that path, or undefined if missing.
|
|
||||||
Traverse obj by dot-separated path name, returning the final value or undefined
|
|
||||||
if any step is missing.
|
|
||||||
`
|
|
||||||
|
|
||||||
util.mergekey = function (o1, o2, k) {
|
util.mergekey = function (o1, o2, k) {
|
||||||
if (!o2) return
|
if (!o2) return
|
||||||
@@ -101,38 +52,17 @@ util.mergekey = function (o1, o2, k) {
|
|||||||
}
|
}
|
||||||
} else o1[k] = o2[k]
|
} else o1[k] = o2[k]
|
||||||
}
|
}
|
||||||
util.mergekey[cell.DOC] = `
|
|
||||||
:param o1: The target object.
|
|
||||||
:param o2: The source object.
|
|
||||||
:param k: The key to merge.
|
|
||||||
:return: None
|
|
||||||
Helper for merge, updating key k from o2 into o1. Arrays are deep-copied and objects are
|
|
||||||
recursively merged.
|
|
||||||
`
|
|
||||||
|
|
||||||
util.merge = function (target, ...objs) {
|
util.merge = function (target, ...objs) {
|
||||||
for (var obj of objs) for (var key of Object.keys(obj)) util.mergekey(target, obj, key)
|
for (var obj of objs) for (var key of Object.keys(obj)) util.mergekey(target, obj, key)
|
||||||
return target
|
return target
|
||||||
}
|
}
|
||||||
util.merge[cell.DOC] = `
|
|
||||||
:param target: The target object.
|
|
||||||
:param objs: One or more objects to merge into target.
|
|
||||||
:return: The updated target object.
|
|
||||||
Merge all passed objects into target, copying or merging each key as needed.
|
|
||||||
Arrays are deep-copied, objects are recursively merged, etc.
|
|
||||||
`
|
|
||||||
|
|
||||||
util.copy = function (proto, ...objs) {
|
util.copy = function (proto, ...objs) {
|
||||||
var c = Object.create(proto)
|
var c = Object.create(proto)
|
||||||
for (var obj of objs) Object.mixin(c, obj)
|
for (var obj of objs) Object.mixin(c, obj)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
util.copy[cell.DOC] = `
|
|
||||||
:param proto: The prototype object for the new object.
|
|
||||||
:param objs: One or more objects whose properties will be mixed in.
|
|
||||||
:return: The newly created object.
|
|
||||||
Create a new object with proto as its prototype, then mix in additional objects’ properties.
|
|
||||||
`
|
|
||||||
|
|
||||||
util.obj_lerp = function(a,b,t) {
|
util.obj_lerp = function(a,b,t) {
|
||||||
if (a.lerp) return a.lerp(b, t)
|
if (a.lerp) return a.lerp(b, t)
|
||||||
@@ -142,14 +72,6 @@ util.obj_lerp = function(a,b,t) {
|
|||||||
})
|
})
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
util.obj_lerp[cell.DOC] = `
|
|
||||||
:param a: The start object (its properties must have .lerp()).
|
|
||||||
:param b: The end object (matching properties).
|
|
||||||
:param t: Interpolation factor (0..1).
|
|
||||||
:return: A new object with interpolated properties.
|
|
||||||
Linearly interpolate between two objects a and b by factor t, assuming each property
|
|
||||||
supports .lerp().
|
|
||||||
`
|
|
||||||
|
|
||||||
util.normalizeSpacing = function normalizeSpacing(spacing) {
|
util.normalizeSpacing = function normalizeSpacing(spacing) {
|
||||||
if (typeof spacing === 'number') {
|
if (typeof spacing === 'number') {
|
||||||
@@ -166,23 +88,6 @@ util.normalizeSpacing = function normalizeSpacing(spacing) {
|
|||||||
return {l:0, r:0, t:0, b:0}
|
return {l:0, r:0, t:0, b:0}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
util.normalizeSpacing[cell.DOC] = `
|
|
||||||
:param spacing: A number, an array of length 2 or 4, or an object with l/r/t/b.
|
|
||||||
:return: An object {l, r, t, b}.
|
|
||||||
Normalize any spacing input into a {l, r, t, b} object.
|
|
||||||
`
|
|
||||||
|
|
||||||
util.guid[cell.DOC] = `
|
|
||||||
:return: A random 32-character string (hex).
|
|
||||||
Return a random 32-character hexadecimal UUID-like string (not guaranteed RFC4122-compliant).
|
|
||||||
`
|
|
||||||
|
|
||||||
util.insertion_sort[cell.DOC] = `
|
|
||||||
:param arr: The array to be sorted in-place.
|
|
||||||
:param cmp: Comparison function cmp(a,b)->Number.
|
|
||||||
:return: The same array, sorted in-place.
|
|
||||||
In-place insertion sort of an array using cmp(a,b)->Number for ordering.
|
|
||||||
`
|
|
||||||
|
|
||||||
function deep_copy(from) {
|
function deep_copy(from) {
|
||||||
return json.decode(json.encode(from))
|
return json.decode(json.encode(from))
|
||||||
|
|||||||
@@ -109,7 +109,6 @@ void actor_free(cell_rt *actor)
|
|||||||
JS_FreeValue(js, actor->message_handle);
|
JS_FreeValue(js, actor->message_handle);
|
||||||
JS_FreeValue(js, actor->on_exception);
|
JS_FreeValue(js, actor->on_exception);
|
||||||
JS_FreeValue(js, actor->unneeded);
|
JS_FreeValue(js, actor->unneeded);
|
||||||
JS_FreeAtom(js, actor->doc_sym);
|
|
||||||
JS_FreeAtom(js, actor->actor_sym);
|
JS_FreeAtom(js, actor->actor_sym);
|
||||||
|
|
||||||
SDL_RemoveTimer(actor->ar);
|
SDL_RemoveTimer(actor->ar);
|
||||||
@@ -705,6 +704,7 @@ static int actor_interrupt_cb(JSRuntime *rt, cell_rt *crt)
|
|||||||
void script_startup(cell_rt *prt)
|
void script_startup(cell_rt *prt)
|
||||||
{
|
{
|
||||||
JSRuntime *rt;
|
JSRuntime *rt;
|
||||||
|
|
||||||
#ifdef TRACY_ENABLE
|
#ifdef TRACY_ENABLE
|
||||||
if (tracy_profiling_enabled)
|
if (tracy_profiling_enabled)
|
||||||
rt = JS_NewRuntime2(&tracy_malloc_funcs, NULL);
|
rt = JS_NewRuntime2(&tracy_malloc_funcs, NULL);
|
||||||
@@ -730,6 +730,9 @@ void script_startup(cell_rt *prt)
|
|||||||
JS_AddIntrinsicJSON(js);
|
JS_AddIntrinsicJSON(js);
|
||||||
JS_AddIntrinsicMapSet(js);
|
JS_AddIntrinsicMapSet(js);
|
||||||
JS_AddIntrinsicProxy(js);
|
JS_AddIntrinsicProxy(js);
|
||||||
|
// JS_AddIntrinsicTypedArrays(js);
|
||||||
|
// JS_AddIntrinsicDate(js);
|
||||||
|
// JS_AddIntrinsicPromise(js);
|
||||||
|
|
||||||
JS_SetContextOpaque(js, prt);
|
JS_SetContextOpaque(js, prt);
|
||||||
prt->context = js;
|
prt->context = js;
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ typedef struct cell_rt {
|
|||||||
int main_thread_only;
|
int main_thread_only;
|
||||||
|
|
||||||
JSAtom actor_sym;
|
JSAtom actor_sym;
|
||||||
JSAtom doc_sym;
|
|
||||||
|
|
||||||
const char *name; // human friendly name
|
const char *name; // human friendly name
|
||||||
} cell_rt;
|
} cell_rt;
|
||||||
|
|||||||
@@ -1585,15 +1585,6 @@ void ffi_load(JSContext *js)
|
|||||||
|
|
||||||
JSValue prosp = JS_NewObject(js);
|
JSValue prosp = JS_NewObject(js);
|
||||||
JS_SetPropertyStr(js,globalThis,"prosperon", prosp);
|
JS_SetPropertyStr(js,globalThis,"prosperon", prosp);
|
||||||
JSValue c_types = JS_NewObject(js);
|
|
||||||
JS_SetPropertyStr(js,prosp, "c_types", c_types);
|
|
||||||
|
|
||||||
QJSCLASSPREP_FUNCS(font);
|
|
||||||
QJSCLASSPREP_FUNCS(datastream);
|
|
||||||
|
|
||||||
JSValue jsobject = JS_GetPropertyStr(js,globalThis, "Object");
|
|
||||||
JS_SetPropertyStr(js, jsobject, "id", JS_NewCFunction(js, js_os_value_id, "id", 1));
|
|
||||||
JS_FreeValue(js,jsobject);
|
|
||||||
|
|
||||||
JSValue jsarray = JS_GetPropertyStr(js,globalThis, "Array");
|
JSValue jsarray = JS_GetPropertyStr(js,globalThis, "Array");
|
||||||
JSValue array_proto = JS_GetPropertyStr(js,jsarray, "prototype");
|
JSValue array_proto = JS_GetPropertyStr(js,jsarray, "prototype");
|
||||||
@@ -1607,9 +1598,6 @@ void ffi_load(JSContext *js)
|
|||||||
JS_FreeValue(js,jsnumber);
|
JS_FreeValue(js,jsnumber);
|
||||||
JS_FreeValue(js,number_proto);
|
JS_FreeValue(js,number_proto);
|
||||||
|
|
||||||
//JS_SetPropertyStr(js,prosp, "version", JS_NewString(js,CELL_VERSION));
|
|
||||||
//JS_SetPropertyStr(js,prosp,"revision",JS_NewString(js,CELL_COMMIT));
|
|
||||||
|
|
||||||
JSValue hidden_fn = JS_NewObject(js);
|
JSValue hidden_fn = JS_NewObject(js);
|
||||||
// add engine.js-only functions to hidden_fn. It should grab them and then remove so nothing else can use them.
|
// add engine.js-only functions to hidden_fn. It should grab them and then remove so nothing else can use them.
|
||||||
|
|
||||||
@@ -1636,11 +1624,6 @@ void ffi_load(JSContext *js)
|
|||||||
actor->actor_sym = JS_ValueToAtom(js, actorsym);
|
actor->actor_sym = JS_ValueToAtom(js, actorsym);
|
||||||
JS_SetPropertyStr(js, hidden_fn, "ACTORDATA", JS_DupValue(js,actorsym));
|
JS_SetPropertyStr(js, hidden_fn, "ACTORDATA", JS_DupValue(js,actorsym));
|
||||||
JS_FreeValue(js, actorsym);
|
JS_FreeValue(js, actorsym);
|
||||||
JSValue docsym = js_newsymbol(js, "+documentation+", 0);
|
|
||||||
actor->doc_sym = JS_ValueToAtom(js, docsym);
|
|
||||||
JS_SetPropertyStr(js, hidden_fn, "DOCSYM", JS_DupValue(js,docsym));
|
|
||||||
JS_FreeValue(js,docsym);
|
|
||||||
|
|
||||||
JS_SetPropertyStr(js, prosp, "hidden", hidden_fn);
|
JS_SetPropertyStr(js, prosp, "hidden", hidden_fn);
|
||||||
|
|
||||||
JS_FreeValue(js,globalThis);
|
JS_FreeValue(js,globalThis);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ JSC_CCALL(js_eval_compile,
|
|||||||
#include "qjs_blob.h"
|
#include "qjs_blob.h"
|
||||||
|
|
||||||
JSC_CCALL(js_compile_blob,
|
JSC_CCALL(js_compile_blob,
|
||||||
// JSRuntime *rt = JS_GetRuntime(js);
|
JSRuntime *rt = JS_GetRuntime(js);
|
||||||
// JS_SetStripInfo(rt, JS_STRIP_SOURCE);
|
// JS_SetStripInfo(rt, JS_STRIP_SOURCE);
|
||||||
// JS_SetStripInfo(rt, JS_STRIP_DEBUG);
|
// JS_SetStripInfo(rt, JS_STRIP_DEBUG);
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|||||||
Reference in New Issue
Block a user