Finish JerryScript Entity/Scene wiring; remove JSON serialize/deserialize
Register Entity, the generic Component wrapper, and Scene as JerryScript classes (modulelist.c ties them together, plus their .d.ts stubs), so scenes/entities can be built from script going forward instead of the JSON scene format. With scripting now the intended authoring path, drop the JSON serialize/deserialize machinery entirely: componentdefinition_t's serialize/deserialize callbacks, every component's *Serialize/ *Deserialize function, entitySerialize/entityDeserialize, sceneSerialize/sceneDeserialize, and the "prefabs/<name>.json"/ "scenes/<name>.json" asset fallback in entityPrefabResolveAndApply/ scenePrefabResolveAndApply (C-coded prefabs only now). physicsshape.c and its test are removed outright since they only existed for this. game.c's test scene now comes from the existing overworldSceneCreate() C builder instead of loading the now-deleted assets/scenes/test.json. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -188,21 +188,85 @@ simply left undefined — the core guards calls with `#ifdef`.
|
||||
## Adding a new entity component
|
||||
1. Create `src/dusk/entity/component/<category>/entityMyComp.h/.c` with
|
||||
struct `entityMyComp_t`, `entityMyCompInit()`, and optionally
|
||||
`entityMyCompDispose()`.
|
||||
2. Add the include to `src/dusk/entity/componentlist.h` header block.
|
||||
3. Add a row to `src/dusk/entity/componentlist.h`:
|
||||
`entityMyCompDispose()`, `entityMyCompRender()`.
|
||||
2. Add the include to `src/dusk/entity/componentlist.h` header block
|
||||
(or `src/duskrpg/entity/gamecomponentlist.h` for a game-specific
|
||||
component, appended after the engine's inbuilt ones).
|
||||
3. Add a row:
|
||||
```c
|
||||
X(MYCOMP, entityMyComp_t, myComp, entityMyCompInit, NULL, NULL)
|
||||
```
|
||||
This auto-generates the enum, union field, and definition entry.
|
||||
Params are `(enumName, type, field, init, dispose, render)` — pass
|
||||
`NULL` for any callback the component doesn't need. This
|
||||
auto-generates the enum, union field, and definition entry.
|
||||
4. If JS-facing, create the script module and `.d.ts` (see below).
|
||||
|
||||
Entities/components/scenes have no JSON serialize/deserialize path —
|
||||
that was removed in favor of building scenes from C-coded prefabs
|
||||
(below) or from JerryScript (`Entity`/`Component`/`Scene`, see
|
||||
"Adding a new script (JS) module").
|
||||
|
||||
---
|
||||
|
||||
## Adding a new entity/scene prefab
|
||||
Entity prefabs (`src/dusk/entity/entityprefab.h`) and scene prefabs
|
||||
(`src/dusk/scene/sceneprefab.h`) follow the same pattern:
|
||||
1. Write an apply function: `errorret_t entityPrefabXxxApply(mgr,
|
||||
entityId)` (or `errorret_t scenePrefabXxxApply(sceneId)`), building
|
||||
up the entity/scene with the normal component/entity APIs.
|
||||
2. Add an entry to the sentinel-terminated `ENTITY_PREFABS[]` (in
|
||||
`src/dusk/entity/entityprefablist.h`, or a game-specific list it
|
||||
includes) or `SCENE_PREFABS[]`:
|
||||
```c
|
||||
{ .name = "MY_PREFAB", .extends = "", .apply = entityPrefabXxxApply }
|
||||
```
|
||||
`extends` names another prefab to apply first (recurses through
|
||||
`entityPrefabResolveAndApply`/`scenePrefabResolveAndApply`), or `""`
|
||||
for none. Do not add an enum or count field — the array is iterated
|
||||
until `.name[0] == '\0'`.
|
||||
3. `entityPrefabResolveAndApply`/`scenePrefabResolveAndApply` only
|
||||
resolve names against the C-coded registry above — there is no JSON
|
||||
asset fallback. Throws if no prefab with that name is registered.
|
||||
|
||||
---
|
||||
|
||||
## Adding a new cutscene item type
|
||||
1. Create `src/duskrpg/cutscene/item/<category>/cutsceneMyItem.h/.c`
|
||||
with a data struct (e.g. `cutscenemyitem_t`) and
|
||||
`cutsceneMyItemStart(item, data)` / `cutsceneMyItemUpdate(item,
|
||||
data)` (the latter returns `true` once the item has completed). Add
|
||||
a matching `cutscenemyitemdata_t` runtime-data struct only if the
|
||||
item needs per-run state across ticks (most don't).
|
||||
2. Add `CUTSCENE_ITEM_TYPE_MY_ITEM` to the enum and a union member to
|
||||
`cutsceneitem_t` (and `cutsceneitemdata_t` if it has runtime data) in
|
||||
`src/duskrpg/cutscene/item/cutsceneitem.h`.
|
||||
3. Register the `{ start, update }` pair in `CUTSCENE_ITEM_CALLBACKS[]`
|
||||
in `cutsceneitem.c`.
|
||||
4. Add an authoring macro to `src/duskrpg/cutscene/cutscene.h`:
|
||||
```c
|
||||
#define CUTSCENE_MY_ITEM(ARGS...) \
|
||||
{ .type = CUTSCENE_ITEM_TYPE_MY_ITEM, .myItem = { ARGS } }
|
||||
```
|
||||
used inside a `CUTSCENE(NAME, SIZE, PAUSE_TYPE, ...)` block.
|
||||
|
||||
---
|
||||
|
||||
## Adding a new script (JS) module
|
||||
Dusk embeds JerryScript (`src/dusk/script/`, fetched via
|
||||
`cmake/modules/Findjerryscript.cmake`). Today only `Entity`, the
|
||||
generic `Component` wrapper, and `Scene` are registered (see
|
||||
`src/dusk/script/module/modulelist.c`) — no per-component-type typed
|
||||
wrappers exist yet (e.g. no `.position` on a `POSITION` component);
|
||||
`entity.add(TYPE)`/`entity.getComponent(TYPE)` always return the
|
||||
generic `Component`.
|
||||
|
||||
1. Create `src/dusk/script/module/<category>/moduleMyMod.h/.c`.
|
||||
- Declare `extern scriptproto_t MODULE_MYMOD_PROTO;` in the header.
|
||||
- Use `moduleBaseFunction(name)` to define JS-callable functions.
|
||||
- Use `moduleBaseFunction(name)` to define JS-callable functions —
|
||||
these are the one exception to "no `static` in `.c` files": the
|
||||
macro itself expands to a `static jerry_value_t name(...)`
|
||||
JerryScript external-handler trampoline, never called by name
|
||||
from other C files, so it isn't declared in the `.h`.
|
||||
- Register props/funcs in `moduleMyModInit()` with
|
||||
`scriptProtoDefineProp` / `scriptProtoDefineFunc` /
|
||||
`scriptProtoDefineStaticFunc`.
|
||||
@@ -210,9 +274,12 @@ simply left undefined — the core guards calls with `#ifdef`.
|
||||
`src/dusk/script/module/modulelist.c` and call
|
||||
`moduleMyModInit()` in `moduleListInit()` (and `Dispose` in
|
||||
`moduleListDispose()`).
|
||||
3. For component modules also register in
|
||||
`src/dusk/script/module/entity/component/modulecomponentlist.c`
|
||||
so `entity.add()` returns the typed wrapper.
|
||||
3. For a component module that adds a *typed* wrapper for a specific
|
||||
component type, create
|
||||
`src/dusk/script/module/entity/component/modulecomponentlist.c` (it
|
||||
doesn't exist yet — the first such module creates it) so
|
||||
`entity.add()` can return the typed wrapper instead of the generic
|
||||
`Component`.
|
||||
4. Create `types/<category>/mymod.d.ts` and add a
|
||||
`/// <reference path="..." />` line to `types/index.d.ts`.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user