Add Hugo website and rewrite docs to match current engine
New Hugo site in website/ with prosperon.dev theme (blue/gold/castle aesthetic), docs sidebar navigation, and content pages. Rewrote all doc files to align with the actual codebase: compositor+film2d rendering, use() modules (no global prosperon object), Pit language, script+JSON entity model. Added entities.md, front matter to all 70+ API docs, and updated API index for current module architecture. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,47 +1,19 @@
|
||||
---
|
||||
title: "Quickstart"
|
||||
type: docs
|
||||
---
|
||||
|
||||
# Quickstart
|
||||
|
||||
This quickstart walks through running Cell programs, exploring examples, and creating your first module and program. It assumes the `./cell` executable is present at the repo root (already built or downloaded).
|
||||
This quickstart walks through creating modules, programs, and running examples.
|
||||
|
||||
## 1) Initialize a Project Shop (.cell)
|
||||
## Your First Module
|
||||
|
||||
Create the project structure used for module management and bytecode cache:
|
||||
A module (`.cm`) returns a frozen value — an API, a config, data.
|
||||
|
||||
- `./cell init`
|
||||
|
||||
This creates `.cell/` with `cell.toml`, `lock.toml`, `modules/`, `build/`, and `patches/`.
|
||||
|
||||
## 2) Run Built‑in Examples
|
||||
|
||||
Examples under `examples/` are programs (`*.ce`) you can run directly:
|
||||
|
||||
- NAT portal server (introduction service):
|
||||
- `./cell examples/nat`
|
||||
- NAT client (contacts a portal):
|
||||
- `./cell examples/nat_client`
|
||||
- Non‑blocking HTTP download actor:
|
||||
- `./cell examples/http_download_actor`
|
||||
|
||||
Tip: Use these as references for portals, contacts, and non‑blocking I/O.
|
||||
|
||||
## 3) Run the Accio Game
|
||||
|
||||
Accio lives under `accio/`. The program is `accio/accio.ce` and supports modes via arguments:
|
||||
|
||||
- Start menu: `./cell accio start`
|
||||
- Load a level: `./cell accio level game/1.json`
|
||||
- Analyze assets: `./cell accio analyze`
|
||||
- Clean level data: `./cell accio clean`
|
||||
|
||||
Arguments after the program path are available inside the program via `arg` (e.g., `arg[0] == 'start'`).
|
||||
|
||||
## 4) Your First Module (.cm) and Program (.ce)
|
||||
|
||||
Create a module that returns a frozen API object, and a program that uses it.
|
||||
|
||||
- File: `examples/hello.cm` (module)
|
||||
Create `hello.cm`:
|
||||
|
||||
```javascript
|
||||
// Returns a value (frozen by the engine)
|
||||
return {
|
||||
greet: function(name) {
|
||||
return `Hello, ${name}!`
|
||||
@@ -49,39 +21,43 @@ return {
|
||||
}
|
||||
```
|
||||
|
||||
- File: `examples/hello.ce` (program)
|
||||
## Your First Program
|
||||
|
||||
A program (`.ce`) is an entry point. It runs top-to-bottom and can register handlers.
|
||||
|
||||
Create `hello.ce`:
|
||||
|
||||
```javascript
|
||||
var hello = use('examples/hello')
|
||||
var hello = use('hello')
|
||||
|
||||
log.console(hello.greet('Cell'))
|
||||
log.console(hello.greet('Prosperon'))
|
||||
|
||||
$receiver(function(msg) {
|
||||
if (msg.type == 'ping') {
|
||||
send(msg, {type:'pong'})
|
||||
send(msg, {type: 'pong'})
|
||||
}
|
||||
})
|
||||
|
||||
$delay(_ => $stop(), 0.1)
|
||||
```
|
||||
|
||||
Run it:
|
||||
## Modules vs Programs
|
||||
|
||||
- `./cell examples/hello`
|
||||
| | Modules (`.cm`) | Programs (`.ce`) |
|
||||
|---|---|---|
|
||||
| Must return a value | Yes | No |
|
||||
| Return value frozen | Yes | N/A |
|
||||
| Can register handlers | No | Yes (`$receiver`) |
|
||||
| Can spawn children | No | Yes (`$start`) |
|
||||
| Cached after first load | Yes | N/A |
|
||||
|
||||
Notes:
|
||||
- Modules are `*.cm` and must return a value. The engine deep‑freezes return values, so mutate via new objects or closures rather than in‑place.
|
||||
- Programs are `*.ce` and must not return a value. They run top‑to‑bottom when spawned and can register handlers via `$receiver()` and schedule work via `$delay()` or `$clock()`.
|
||||
## Spawning Actors
|
||||
|
||||
## 5) Spawning Child Programs (Actors)
|
||||
|
||||
Programs can spawn other programs and receive lifecycle events.
|
||||
|
||||
- File: `examples/spawner.ce`
|
||||
Programs can spawn other programs as child actors:
|
||||
|
||||
```javascript
|
||||
$receiver(function(e) {
|
||||
if (e.type == 'greet' && e.actor) {
|
||||
if (e.type == 'greet') {
|
||||
log.console('Child greeted me')
|
||||
}
|
||||
})
|
||||
@@ -90,44 +66,46 @@ $start(function(info) {
|
||||
if (info.type == 'greet') {
|
||||
log.console('Spawned child actor')
|
||||
}
|
||||
}, 'examples/hello.ce')
|
||||
}, 'hello.ce')
|
||||
|
||||
$delay(_ => $stop(), 0.5)
|
||||
```
|
||||
|
||||
Run it:
|
||||
## Actor Primitives
|
||||
|
||||
- `./cell examples/spawner`
|
||||
| Primitive | Purpose |
|
||||
|-----------|---------|
|
||||
| `$start(callback, path)` | Spawn a child actor from a program |
|
||||
| `$receiver(callback)` | Register a message handler |
|
||||
| `send(target, message)` | Send a message to an actor |
|
||||
| `$delay(callback, seconds)` | Schedule a one-shot callback |
|
||||
| `$clock(callback, interval)` | Schedule a repeating callback |
|
||||
| `$stop()` | Terminate the current actor |
|
||||
|
||||
## 6) Module Shop Basics
|
||||
## Module Resolution
|
||||
|
||||
The module shop manages vendored dependencies under `.cell/modules/` and caches compiled bytecode under `.cell/build/`.
|
||||
`use('path')` looks for modules in this order:
|
||||
|
||||
Common commands (all are programs under `scripts/`):
|
||||
1. The current module's directory for `path.cm`
|
||||
2. The mounted roots (the program's directory is mounted) for `path.cm`
|
||||
3. Embedded/native modules if no script file is found
|
||||
|
||||
- Initialize (if you haven’t already):
|
||||
- `./cell init`
|
||||
- See available commands:
|
||||
- `./cell help`
|
||||
- Configure system/actor settings:
|
||||
- `./cell config list`
|
||||
- `./cell config set system.reply_timeout 60`
|
||||
- `./cell config actor prosperon/_sdl_video set resolution 1280x720`
|
||||
- Download or vendor dependencies (from `.cell/cell.toml`):
|
||||
- `./cell mod download`
|
||||
Modules compile to bytecode (`.o` files) and are cached for fast reloading.
|
||||
|
||||
## 7) How Module Resolution Works
|
||||
## Example Games
|
||||
|
||||
- `use('path')` checks:
|
||||
1) The current module’s directory for `path.cm` while loading.
|
||||
2) The mounted roots (the program’s directory is mounted) for `path.cm`.
|
||||
3) Embedded/native modules if no script file is found.
|
||||
- Modules compile to `.cell/build/<canonical-path>.o` and reuse the cache if newer than the source.
|
||||
- Scripted modules can extend embedded modules via prototype; if the script returns nothing, the embedded module is used as‑is.
|
||||
Prosperon ships with example games:
|
||||
|
||||
## 8) Next Steps
|
||||
- **Pong** — two-player paddle game
|
||||
- **Snake** — growing snake on a grid
|
||||
- **Tetris** — falling block puzzle
|
||||
- **Chess** — full chess with move validation
|
||||
- **Bunnymark** — sprite rendering benchmark
|
||||
|
||||
- Language details: `docs/cell.md`
|
||||
- Actors, programs, and messaging: `docs/actors.md`
|
||||
- Rendering, input, and resources: `docs/rendering.md`, `docs/input.md`, `docs/resources.md`
|
||||
- Full API reference: `docs/api/`
|
||||
## Next Steps
|
||||
|
||||
- [Tutorial](tutorial/) — Build a game step by step
|
||||
- [Entities](entities/) — The world and entity model
|
||||
- [Rendering](rendering/) — How drawing works
|
||||
- [Input](input/) — Handling player input
|
||||
- [API Reference](api/) — Full module documentation
|
||||
|
||||
Reference in New Issue
Block a user