Skip to content

Commit 2f3bb64

Browse files
committed
Fixed inconsistencies in the docs
1 parent e089a15 commit 2f3bb64

6 files changed

Lines changed: 96 additions & 81 deletions

File tree

Manifest.toml

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Outdoors = "d3598698-a7e3-42d2-87cb-a7a1f294c746"
1515
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1616

1717
[compat]
18+
CRHorizons = "0.1"
1819
EventNotifiers = "1.0"
1920
GDMathLib = "1.3"
2021
Graphs = "1.12,1.13"

docs/Plugins/index.md

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ Cruise.shutdown!(node::CRPluginNode{Sys2}) = setstatus(node, PLUGIN_OFF)
111111

112112
## Merging and Running
113113

114-
Merge the plugin into Cruise at the correct phase:
114+
Merge the plugin into Cruise:
115115

116116
```julia
117-
merge_plugin!(app, plugin, :preupdate)
117+
merge_plugin!(app, plugin)
118118
```
119119

120120
> Even after merging, you can still manage the plugin from the CRPlugin instance you created.
@@ -179,60 +179,6 @@ node.deps[TYPE] # Returns a WeakRef to the capability of the dependency of type
179179

180180
---
181181

182-
### Plugin Serialization
183-
184-
Persistent plugin must overload the serialization functions `encode_state` that outputs a dictionary with exactly 3 top-level sections with the last 2 following the enumeration:
185-
186-
```julia
187-
@enum PluginSerializationInfo begin
188-
PLUGIN_STATE_INFO
189-
PLUGIN_DEBUG_INFO
190-
end
191-
```
192-
193-
1. `PLUGIN_STATE_INFO` : the core runtime state of the plugin. It should provides enough informations for you to reconstruct the data of you `CRPluginNode`.
194-
195-
2. `PLUGIN_DEBUG_INFO`: optional info for debugging, monitoring, or health-checks (e.g., counters, last error, timestamps). Anything that could help debug abnormal behaviors in your plugin.
196-
197-
#### Restoring your plugin's state
198-
199-
You should overload the `restore_state` methods which will have the following signature:
200-
201-
```julia
202-
restore_state(::Val{:YourPluginName}, data::Dict{String, Any})
203-
```
204-
205-
This function should returns an instance of the object contained in your plugin. You will have to use the informations you previously gave to serialize to create your object
206-
207-
#### Serialization Rules
208-
209-
- Non-serializable fields (callbacks, Tasks, WeakRefs) must be skipped.
210-
211-
- `restore_state` must be able to restore both state and data fully.
212-
213-
- debug can be ignored during restore; it is purely informational.
214-
215-
216-
#### Example
217-
218-
```julia
219-
Dict(
220-
"Name" => "TimerPlugin"
221-
PLUGIN_STATE_INFO => Dict("current_time" => 12.5, "active" => true),
222-
PLUGIN_DEBUG_INFO => Dict("last_update" => DateTime("2025-11-08T10:00:00"))
223-
)
224-
```
225-
226-
#### Why this ?
227-
228-
Because it offers:
229-
230-
- Clear separation between runtime, persistent, and debug info
231-
232-
- Easier logging and debugging
233-
234-
- Uniform format for all plugins, making save/load logic generic
235-
236182
### Registering plugin
237183

238184
In order for your plugin to be registered, it need to meet the following guidelines:

docs/Plugins/pauser.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ using Cruise, PausePlugin
6262

6363
app = CruiseApp()
6464

65-
merge_plugin!(app, PAUSEPLUGIN, :preupdate)
65+
merge_plugin!(app, PAUSEPLUGIN)
6666
```
6767

6868
Now we can simply use the plugin in the game loop.

docs/Plugins/timer.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ Now we can happily use our plugin:
111111
```julia
112112
i = 0
113113
@gameloop maxfps=60 begin
114+
LOOP_VAR = LOOP_VAR_REF[]
114115
if LOOP_VAR.frame_idx % 50 == 0
115116
timer = addtimer!(rand())
116117

docs/gamelogics.md

Lines changed: 85 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,105 @@
1-
# Cruise v0.3.0 documentation: Game logics
1+
# Cruise v0.3.0 documentation: Game Logics
22

3-
A game logic is a chunk of code that execute a specific task in your code.
4-
In regular game engines they are often called **scripts**. These scripts are then tied to an object. when the object is active, his script execute, when it's not, the script isn't executed.
3+
A **game logic** is a self-contained block of code that performs a specific task in your game.
4+
In most engines these are called *scripts*, and they’re attached to game objects: if the object is active, its script runs; if not, it doesn’t.
55

6-
With Cruise, it's a little bit different. Scripts are called **game logics** and are independent of objects. They can be activated/desactivated at will. Their purpose is to accomplish a specific task in your game.
6+
Cruise doesn’t follow that model.
7+
Here, a game logic is **not tied to any object**.
8+
It can be enabled or disabled at any time, connected to other logics, and integrated directly into the main execution graph.
9+
Its only responsibility is to perform a clearly defined operation inside your game.
710

8-
One can create a new game logic like this
11+
---
12+
13+
## Declaring a Game Logic
914

1015
```julia
11-
app = CruiseApp() # Make sure to have called this at least once
16+
app = CruiseApp() # Must be called at least once
1217

1318
logic_id = @gamelogic logic_name begin
14-
# My code
19+
# Logic code
1520
end
1621
```
1722

18-
So here we made a new game logic that we named `logic_name`. The `@gamelogic` macro will return the id of our new logic.
19-
Why an id ?
20-
Because a game logic is in fact a system in the main plugin graph. This means that all your logic benefits from all the features a regular plugin node have (capabilities, dependencies, enabling/disabling, etc). Your logic is automatically added to the main plugin, but you can optionnaly pas the keyword argument `plugin=myplugin` so the logic is added to your custom plugin instead.
23+
`@gamelogic` creates the logic, registers it inside the plugin graph, and returns its **ID**.
24+
Why an ID?
25+
Because a game logic is essentially a **system node in the main plugin graph**, with all the same features as any plugin node:
26+
27+
* capabilities
28+
* dependencies
29+
* enable/disable
30+
* ordered execution
2131

22-
Each game logic is an intace of the object `GameCode{Name}` where `Name` is the name of your logic as a `Symbol`.
23-
So when getting it from adependency for example, you will just do
32+
By default, the logic is added to the main plugin, but you can place it elsewhere:
2433

2534
```julia
26-
pluginnode.deps[GameCode{:name}]
35+
@gamelogic logic_name plugin=myplugin begin
36+
...
37+
end
38+
```
39+
40+
---
41+
42+
## Identity and Access
43+
44+
Each logic is an instance of:
45+
46+
```
47+
GameCode{Name}
2748
```
2849

29-
In your logics, the internal representation of your logic (the node of the graph) is called `self`. for example
50+
where `Name` is your logic’s name as a `Symbol`.
51+
52+
Example: accessing it from a dependency list:
53+
54+
```julia
55+
pluginnode.deps[GameCode{:logic_name}]
56+
```
57+
58+
---
59+
60+
## The `self` Variable
61+
62+
Inside every game logic, Cruise injects a variable called `self`.
63+
This is the actual node in the plugin graph that represents your system.
3064

3165
```julia
3266
@gamelogic logic begin
33-
println(self) # self are is a variable specific to the logic that is the node containing the logic
34-
# You can use it as with any other node
67+
println(self) # The node itself
68+
# You can use it exactly like any other graph node
3569
end
3670
```
71+
72+
`self` gives you:
73+
74+
* access to your capability
75+
* access to your dependencies
76+
* node state information
77+
* full interaction with the graph
78+
79+
---
80+
81+
## Keyword Arguments
82+
83+
Game logics accept several optional keywords:
84+
85+
### `mainthread=false`
86+
87+
Forces the system to always run on the main thread.
88+
89+
### `plugin=<plugin>`
90+
91+
Places the logic inside a specific plugin instead of the main one.
92+
93+
### `capability=<obj>`
94+
95+
Associates a capability to the logic.
96+
Other systems depending on this logic can query that capability.
97+
98+
Example:
99+
100+
```julia
101+
@gamelogic movement capability=MovementCap() begin
102+
# ...
103+
end
104+
```
105+

0 commit comments

Comments
 (0)