Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .agents/skills/mirai-agent-api/references/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,13 @@ the GPU passes and the conditions of the measurement. The editor keeps the last
(`settings.set` or open without `--validation`). `allow_limited:true` measures anyway and the
summary says `comparable:false`; a headless editor waits for neither the display nor a limit.
- `profile.compare` gives `comparable:false` with a blocking difference in conditions or if either
of the two is not `comparable`.
of the two is not `comparable`. `profile.save` keeps what it reads of a capture as a baseline of
the project, by name, in `.mirai/profiles/baselines` outside git, and `profile.compare` takes it
with `baseline` in a later session. A baseline file has a format version: one of another
version, or that is not one, is refused and is saved again.
- The `owner` of a zone is whoever declares the loop function it measures (`Step_Info.game` and
`plugin`, which the generator writes): `Game`, `Plugin` with its name, or `Engine` for any other
zone. GPU passes have none: a pass does not know who added it.
- `profile.load` answers about the last load of the document (`scene.open`, a scene a game asks
for), of Play (`play.start`) and of a section, without recording anything first
([loads](../../mirai-core/references/host.md#the-frame)): `ready_ms` until it was the document
Expand Down
3 changes: 2 additions & 1 deletion cook/build/contracts_test.odin
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ functions_are_called_from_the_loops_and_from_their_order :: proc(t:^testing.T) {
testing.expect(t,strings.contains(text,"game_fixed :: proc(world,shared,editor:rawptr,app_data:rawptr) {\n call_clock_read(world,shared,editor,app_data)\n call_things_move(world,shared,editor,app_data)\n}"),text)
testing.expect(t,strings.contains(text,"@(rodata) order_game_fixed:=[2]i32{1,0}"),text)
testing.expect(t,strings.contains(text,"info.loops[.Game][.Late],info.order[.Game][.Late]=game_late,order_game_late[:]"),text)
testing.expect(t,strings.contains(text,"steps[0]={\"things_move\",\"core\",{.Fixed,.Late,},{.Game,.Editor,},call_things_move}"),text)
step:=step_written(text,"things_move")
testing.expect(t,strings.contains(step,"phases={.Fixed,.Late,}") && strings.contains(step,"loops={.Game,.Editor,}"),step)
}
defaulted:=`package core
@(storage) Clock :: struct {tick:u64}
Expand Down
2 changes: 1 addition & 1 deletion cook/build/minds_test.odin
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Zombie_Act :: enum u8 {Wander,Chase,Circle}
call=call[:strings.index(call,"\n}\n")]
testing.expect(t,strings.contains(call,"if w.network.role==.Client {return}"),call)
testing.expect(t,strings.contains(call,"p_core.table_settle(&w.hunger,&w.entities)"),call)
testing.expect(t,strings.contains(text,`steps[0]={"zombie_think","game",{.Fixed,},{.Game,},call_zombie_think}`),"its step is named after its think")
testing.expect(t,strings.contains(step_written(text,"zombie_think"),"call=call_zombie_think"),"its step is named after its think")
}
}

Expand Down
16 changes: 15 additions & 1 deletion cook/build/stages_test.odin
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ import "mirai:core"
for gone in ([]string{"Step_Edge","info.edges","info.parallel","worker"}) {
testing.expectf(t,!strings.contains(text,gone),"the generated world still says %s",gone)
}
testing.expect(t,strings.contains(text,"steps[0]={\"core_last\",\"core\",{.Fixed,},{.Game,},call_core_last}"),text)
// A step says who declares it: an engine package, or the game of the project.
last,logic:=step_written(text,"core_last"),step_written(text,"game_logic")
testing.expect(t,strings.contains(last,"phases={.Fixed,}") && strings.contains(last,"call=call_core_last"),last)
testing.expect(t,strings.contains(last,`plugin=""`) && strings.contains(last,"game=false"),last)
testing.expect(t,strings.contains(logic,"game=true"),logic)
// What game_spawn made is settled inside its call, before game_count is called.
_,_,rest:=strings.partition(text,"call_game_spawn :: proc(world,shared,editor:rawptr,app_data:rawptr) {")
body,_,_:=strings.partition(rest,"\n}\n")
Expand Down Expand Up @@ -295,3 +299,13 @@ import "mirai:core"
output=world_generate(&p,context.temp_allocator)
testing.expectf(t,errors_have(output.errors,"game_decide is server, and the world has no core.Network"),"%v",output.errors)
}

// The row of info.steps the generated world writes for a function, by
// name: its fields, whatever their order.
@(private)
step_written :: proc(text,name:string) -> string {
at:=strings.index(text,fmt.tprintf("={{name=%q,",name))
if at<0 {return ""}
row:=text[at:]
return row[:strings.index_byte(row,'\n')]
}
14 changes: 9 additions & 5 deletions cook/build/world.odin
Original file line number Diff line number Diff line change
Expand Up @@ -2374,7 +2374,7 @@ world_write :: proc(g:^Generator,editor:bool) -> string {
for r,ri in g.records {
tag:=fmt.tprintf("%s_%s",snake(r.pkg.name),snake(r.name))
_,has_default:=record_default(r)
game:=strings.has_prefix(r.pkg.path,"project:") && !strings.has_prefix(r.pkg.path,"project:plugins/")
game:=game_package(r.pkg)
fmt.sbprintf(w," records[%d]={{\"%s\",\"%s\",typeid_of(%s.%s),type_info_of(%s.%s),typeid_of(%s.Record(%s.%s)),%s,%v}}\n",ri,r.name,r.pkg.name,r.pkg.alias,r.name,r.pkg.alias,r.name,core_alias,r.pkg.alias,r.name,has_default?fmt.tprintf("record_default_%s",tag):"nil",game)
}
codes:=record_codes(g)
Expand All @@ -2389,7 +2389,7 @@ world_write :: proc(g:^Generator,editor:bool) -> string {
loop_set:=strings.builder_make(context.temp_allocator)
if s.loops[0] {strings.write_string(&loop_set,".Game,")}
if s.loops[1] {strings.write_string(&loop_set,".Editor,")}
fmt.sbprintf(w," steps[%d]={{\"%s\",\"%s\",{{%s}},{{%s}},call_%s}}\n",si,s.name,s.pkg.name,strings.to_string(phase_set),strings.to_string(loop_set),s.name)
fmt.sbprintf(w," steps[%d]={{name=%q,library=%q,phases={{%s}},loops={{%s}},call=call_%s,plugin=%q,game=%v}}\n",si,s.name,s.pkg.name,strings.to_string(phase_set),strings.to_string(loop_set),s.name,project.import_plugin(s.pkg.path),game_package(s.pkg))
}
fmt.sbprintf(w," draws:=make([]%s.Draw_Info,%d)\n",core_alias,len(g.draws))
for d,di in g.draws {fmt.sbprintf(w," draws[%d]={{%q,rawptr(%s.%s)}}\n",di,d.name,d.pkg.alias,d.ident)}
Expand Down Expand Up @@ -2467,12 +2467,16 @@ type_procs_write :: proc(w:^strings.Builder,t:^Type,c:string) {
t.procs=strings.to_string(list)
}

// Whether the game of a project declares a type, not the engine or a plugin.
// Whether a package is of the game of a project, not of the engine or a plugin.
@(private="file")
of_game :: proc(t:^Type) -> bool {
return t.pkg!=nil && strings.has_prefix(t.pkg.path,"project:") && !strings.has_prefix(t.pkg.path,"project:plugins/")
game_package :: proc(pkg:^Package) -> bool {
return pkg!=nil && strings.has_prefix(pkg.path,"project:") && !strings.has_prefix(pkg.path,"project:plugins/")
}

// Whether the game of a project declares a type.
@(private="file")
of_game :: proc(t:^Type) -> bool {return game_package(t.pkg)}

// The row of info.tables of a table of a type, after type_procs_write: name,
// what the scene file and the API call it; offset, where it is in the struct
// of its place. named: its fields go by name, as those of a test world do:
Expand Down
2 changes: 2 additions & 0 deletions core/world.odin
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ Step_Info :: struct {
phases:Phases,
loops:Loops,
call:Step_Proc, // the function as its loops call it: its binding, its settle and its time
plugin:string, // the plugin whose package declares it; empty for the engine and the project
game:bool, // the game of the project declares it, not the engine or a plugin
}

// A procedure @(draw="name") of the game: what draws the Draw nodes of the
Expand Down
2 changes: 1 addition & 1 deletion editor/ai_context.odin
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ ai_prompt_stable :: proc(s:^Session,kind:ai_store.Conversation_Kind) -> string {
strings.write_string(&b,": read the declarations there for the types and procedures you use, not the sources of the engine.\n")
}
strings.write_string(&b,"- You may read files outside the project only to import them, as when the user names a model in Downloads or an image in Pictures: `asset_import` takes the path wherever it is and writes the assets into the project, in `folder` when given; it answers when it ends with what it wrote. Deleting a file asks the user first and moving one does not; delete an asset with `asset_delete`, which moves it to the trash, after `asset_users` says what uses it.\n")
strings.write_string(&b,"- When the game is slow or the user asks about performance, measure instead of guessing: `profile.capture` records frames and answers with what bounds them, the costliest functions, GPU passes and notes on how to read them; `profile.frames` and `profile.zone` explain a spike or a function, and `profile.compare` says whether a change helped. With VSync or a frame limit on it refuses and says how to turn them off; `allow_limited` measures anyway, and then read `cpu_ms` and the functions rather than the frame time.\n")
strings.write_string(&b,"- When the game is slow or the user asks about performance, measure instead of guessing: `profile.capture` records frames and answers with what bounds them, the costliest functions, GPU passes and notes on how to read them; `profile.frames` and `profile.zone` explain a spike or a function, and `profile.compare` says whether a change helped. With VSync or a frame limit on it refuses and says how to turn them off; `allow_limited` measures anyway, and then read `cpu_ms` and the functions rather than the frame time. Each zone says its `owner`: `Game` and the plugins of the project are code the project can change, the others are not. Compare the numbers with the target the user gives; `profile.save` keeps a capture as a baseline that `profile.compare` takes in a later session.\n")
strings.write_string(&b,"- Saved games of the project: `save.list` reads their slots and `save.delete` removes one; `save.write` and `save.load` save and load your run of the game as the game asks for it, so start it with `play.start` first.\n")
if gameplay:=project.path(engine,".agents/skills/mirai-gameplay/SKILL.md",allocator=context.temp_allocator);engine!="" && os.is_file(gameplay) {
fmt.sbprintf(&b,"- Only when you write game code, read %s and the references it links; it is the only engine documentation you need. Editing the scene does not need it.\n",gameplay)
Expand Down
Loading
Loading