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>
112 lines
2.5 KiB
Markdown
112 lines
2.5 KiB
Markdown
---
|
|
title: "Quickstart"
|
|
type: docs
|
|
---
|
|
|
|
# Quickstart
|
|
|
|
This quickstart walks through creating modules, programs, and running examples.
|
|
|
|
## Your First Module
|
|
|
|
A module (`.cm`) returns a frozen value — an API, a config, data.
|
|
|
|
Create `hello.cm`:
|
|
|
|
```javascript
|
|
return {
|
|
greet: function(name) {
|
|
return `Hello, ${name}!`
|
|
}
|
|
}
|
|
```
|
|
|
|
## 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('hello')
|
|
|
|
log.console(hello.greet('Prosperon'))
|
|
|
|
$receiver(function(msg) {
|
|
if (msg.type == 'ping') {
|
|
send(msg, {type: 'pong'})
|
|
}
|
|
})
|
|
|
|
$delay(_ => $stop(), 0.1)
|
|
```
|
|
|
|
## Modules vs Programs
|
|
|
|
| | 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 |
|
|
|
|
## Spawning Actors
|
|
|
|
Programs can spawn other programs as child actors:
|
|
|
|
```javascript
|
|
$receiver(function(e) {
|
|
if (e.type == 'greet') {
|
|
log.console('Child greeted me')
|
|
}
|
|
})
|
|
|
|
$start(function(info) {
|
|
if (info.type == 'greet') {
|
|
log.console('Spawned child actor')
|
|
}
|
|
}, 'hello.ce')
|
|
|
|
$delay(_ => $stop(), 0.5)
|
|
```
|
|
|
|
## Actor Primitives
|
|
|
|
| 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 |
|
|
|
|
## Module Resolution
|
|
|
|
`use('path')` looks for modules in this order:
|
|
|
|
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
|
|
|
|
Modules compile to bytecode (`.o` files) and are cached for fast reloading.
|
|
|
|
## Example Games
|
|
|
|
Prosperon ships with example games:
|
|
|
|
- **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
|
|
|
|
## 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
|