ci-platforms / darwin amd64 smoke (push) Skipped
GitHub / linux amd64 native GitHub-hosted native CI: success
ci-platforms / windows amd64 smoke (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: success
GitHub / darwin arm64 native GitHub-hosted native CI: success
GitHub / darwin amd64 native GitHub-hosted native CI: success
ci / checks (push) Failing after 1h21m34s
ci / native-authoring (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 12m4s
ci / release (push) Skipped
Add dockable Art tools, animation and previews, guarded asset workflows, and the Web Asset Studio built on the shared Art Core. Expand English and Russian documentation, interactive Try scenes, examples and editor icons. Add audio waveform navigation, source analysis, guarded previews and a browser Worker mixer. Preserve source changes and recovery with bounded checks, and strengthen native, browser and interoperability CI. Prepare version 0.12.5 and manually built native artifact candidates. Fix the production site image demo build dependency. Reuse immutable scene indices when capturing keyframes. Wait for real Persist save/load completion in component tests. Stabilize browser Game View captures outside pointer hover. Aseprite interchange and persistent Audio EDL recovery remain limited; the artifact workflow does not publish releases or change stable.
268 lines
7.5 KiB
Go
268 lines
7.5 KiB
Go
package app
|
|
|
|
import (
|
|
"aego/engine/base"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"aego/app/assembly"
|
|
"aego/app/assembly/builtin"
|
|
"aego/app/docicons"
|
|
"aego/asset/loader"
|
|
"aego/asset/pipeline"
|
|
"aego/contracts/persistence"
|
|
"aego/core/errs"
|
|
"aego/core/log"
|
|
"aego/engine"
|
|
"aego/engine/docs"
|
|
"aego/engine/module"
|
|
"aego/engine/problems"
|
|
"aego/engine/settings"
|
|
scriptsystems "aego/modules/scripting/systems"
|
|
"aego/platform"
|
|
"aego/project"
|
|
"aego/render"
|
|
renderhost "aego/render/host"
|
|
"aego/render/sprite"
|
|
"aego/save"
|
|
"aego/scene"
|
|
"aego/scene/frame"
|
|
"aego/script/bind"
|
|
"aego/script/bind/manifest"
|
|
"aego/script/workspace"
|
|
)
|
|
|
|
type Config struct {
|
|
Engine engine.Config
|
|
Logger *log.Logger
|
|
Debug bool
|
|
LoopScope engine.SystemScope
|
|
LocateBindings bool
|
|
Docs bool
|
|
Editor bool
|
|
FailOnScriptErrors bool
|
|
Catalog assembly.Catalog
|
|
Platform platform.Platform
|
|
Profile string
|
|
NoProfile bool
|
|
// NoExternalImportTools prevents project assets from starting external
|
|
// converters and validators, including on later reimport.
|
|
NoExternalImportTools bool
|
|
// SharedIndex opens the asset index read-only without a warning when another process, the editor, holds it.
|
|
SharedIndex bool
|
|
}
|
|
|
|
type Host struct {
|
|
Project *project.Project
|
|
Engine *engine.Engine
|
|
Pipeline *pipeline.Pipeline
|
|
Loader *loader.Loader
|
|
Renderer *render.Renderer
|
|
RenderStats func() render.Stats
|
|
Types *scene.Types
|
|
Bindings *bind.Registry
|
|
Workspace *workspace.Workspace
|
|
Modules *module.Manifest
|
|
Sections *module.Sections
|
|
Problems *problems.Service
|
|
Docs *docs.Registry
|
|
Importers *pipeline.ImporterRegistry
|
|
Log *log.Logger
|
|
Settings *settings.Store
|
|
ProfilePath string
|
|
closed bool
|
|
}
|
|
|
|
func Build(p *project.Project, cfg Config, mods ...module.Module) (*Host, error) {
|
|
lg := cfg.Logger
|
|
if lg == nil {
|
|
lg = log.New(log.NewTextSink(os.Stderr))
|
|
if cfg.Debug {
|
|
lg.SetLevel(log.Debug)
|
|
}
|
|
}
|
|
h := &Host{Project: p, Log: lg}
|
|
if err := h.build(cfg, mods); err != nil {
|
|
h.Close()
|
|
return nil, err
|
|
}
|
|
return h, nil
|
|
}
|
|
|
|
func (h *Host) build(cfg Config, mods []module.Module) error {
|
|
p, lg := h.Project, h.Log
|
|
ch := lg.With(log.Engine)
|
|
var err error
|
|
if h.Workspace, err = workspace.Open(workspace.Config{Root: p.Root, Module: p.Module, Scripts: p.ScriptsDir()}); err != nil {
|
|
return err
|
|
}
|
|
ropt := render.Options{MaxSprites: 65536}
|
|
if cfg.Editor {
|
|
ropt.SpriteLimit = sprite.MaxSubmission
|
|
}
|
|
rmod := renderhost.New(ropt)
|
|
ecfg := cfg.Engine
|
|
if ecfg.ResRoot == "" {
|
|
ecfg.ResRoot = p.AssetsDir()
|
|
}
|
|
if cfg.LoopScope != 0 {
|
|
ecfg.LoopScope = cfg.LoopScope
|
|
}
|
|
builder := engine.NewBuilder(ecfg).WithLogger(lg).Use(rmod)
|
|
if cfg.Platform != nil {
|
|
builder.WithPlatform(cfg.Platform)
|
|
}
|
|
if h.Types, err = assembly.NewTypes(); err != nil {
|
|
return err
|
|
}
|
|
h.Bindings = bind.New()
|
|
h.Bindings.Locate(cfg.LocateBindings)
|
|
if err = frame.Register(builder.Registry()); err != nil {
|
|
return err
|
|
}
|
|
cat := cfg.Catalog
|
|
if cat == nil {
|
|
cat = builtin.Default()
|
|
}
|
|
if h.Modules, err = cat.Load(h.Types, h.Bindings, assembly.Options{}, mods...); err != nil {
|
|
return err
|
|
}
|
|
if h.Sections, err = h.Modules.LoadSections(p.Block, project.CoreBlocks...); err != nil {
|
|
return err
|
|
}
|
|
if ts, ok := module.SectionValue[base.Settings](h.Sections, base.Section); ok {
|
|
builder.Configure(ts.Apply)
|
|
}
|
|
builder.Use(h.Modules.Engine())
|
|
if h.Importers, err = DevImporters(h.Workspace, h.Modules); err != nil {
|
|
return err
|
|
}
|
|
if cfg.NoExternalImportTools {
|
|
disableExternalImportTools(h.Importers)
|
|
}
|
|
if err = h.Types.Schema().Freeze(); err != nil {
|
|
return err
|
|
}
|
|
if err = scriptsystems.Freeze(h.Bindings, h.Types.Schema()); err != nil {
|
|
return errs.Wrap(err, errs.EngineModule, "script bindings are invalid")
|
|
}
|
|
h.Workspace.SetBindings(h.Bindings.Table())
|
|
if cfg.Docs {
|
|
m, derr := manifest.FromRegistry(h.Bindings, h.Types.Schema())
|
|
if derr != nil {
|
|
ch.Warn("cannot describe the script bindings", log.F("err", derr.Error()))
|
|
} else {
|
|
h.Docs = docs.FromManifest(m, h.Types.Schema(), h.Modules)
|
|
h.Docs.SetNavigationIcons(docicons.Builtin())
|
|
m.Keywords = h.Docs.Keywords()
|
|
h.Workspace.SetDocs(m)
|
|
for _, p := range h.Docs.Problems() {
|
|
ch.Warn("documentation: "+p.Message, log.F("entry", p.ID))
|
|
}
|
|
}
|
|
}
|
|
var popts []pipeline.Option
|
|
if cfg.SharedIndex {
|
|
popts = append(popts, pipeline.ExpectShared())
|
|
}
|
|
if h.Pipeline, err = pipeline.Open(p, h.Importers, lg, popts...); err != nil {
|
|
return err
|
|
}
|
|
if _, _, err = h.Pipeline.Scan(); err != nil {
|
|
return err
|
|
}
|
|
batch, err := h.Pipeline.ImportAll()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for id, ierr := range batch.Failed {
|
|
ch.Error("asset import failed", log.F("asset", id.String()), log.F("err", ierr.Error()))
|
|
}
|
|
if cfg.FailOnScriptErrors {
|
|
if bad := ScriptErrors(h.Pipeline); len(bad) > 0 {
|
|
msg := strings.Join(bad, "\n")
|
|
if si := ScriptImporter(h.Importers); si != nil {
|
|
if r := si.Report(); r != "" {
|
|
msg = r
|
|
}
|
|
}
|
|
return errs.New(errs.BuildFailed, "script packages have errors, fix them before running:\n"+msg)
|
|
}
|
|
}
|
|
if h.Engine, err = builder.Build(); err != nil {
|
|
return err
|
|
}
|
|
h.Renderer = rmod.Renderer()
|
|
h.RenderStats = rmod.Stats
|
|
h.Loader = loader.New(h.Engine.GPU(), h.Renderer.Textures(), lg)
|
|
h.Loader.SetMaterials(h.Renderer.Materials())
|
|
if err = h.Loader.Mount(h.Pipeline.Index(), h.Pipeline.Artifacts()); err != nil {
|
|
return err
|
|
}
|
|
h.Engine.SetService(loader.ServiceID, h.Loader)
|
|
h.Engine.SetService(renderhost.ServiceID, h.Renderer)
|
|
h.Problems = problems.New()
|
|
h.Problems.Add(rmod.ShaderProblems())
|
|
h.Problems.Add(MetaProblems(h.Pipeline))
|
|
h.Problems.Add(ShaderProblems(h.Importers))
|
|
h.Problems.Add(h.Modules.AssetProblems(h.Types.Schema(), h.Loader))
|
|
h.Engine.SetService(problems.ServiceID, h.Problems)
|
|
if h.Settings, err = h.Modules.NewSettings(); err != nil {
|
|
return err
|
|
}
|
|
h.Settings.SetNames(h.Sections.Names)
|
|
h.Engine.SetService(settings.ServiceID, h.Settings)
|
|
h.Engine.OnClose(h.Modules.Shutdown)
|
|
if err = h.Modules.Init(&module.InitContext{Engine: h.Engine, Assets: h.Loader, Log: lg, Editor: cfg.Editor, Sections: h.Sections, Problems: h.Problems, Settings: h.Settings,
|
|
GameName: p.Module, GameVersion: p.GameVersion}); err != nil {
|
|
return err
|
|
}
|
|
h.Settings.Freeze()
|
|
h.Settings.LoadProject(p.Settings, project.FileName)
|
|
if !cfg.NoProfile {
|
|
h.loadProfile(cfg.Profile, ch)
|
|
}
|
|
h.Problems.Add(h.Settings.Problems())
|
|
h.Settings.Start()
|
|
for _, w := range h.Modules.Warnings {
|
|
ch.Warn(w)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (h *Host) loadProfile(name string, ch *log.ChannelLogger) {
|
|
path, err := platform.ProfilePath(h.Project.Module, name)
|
|
if err != nil {
|
|
ch.Warn("player settings are not saved", log.F("err", err.Error()))
|
|
return
|
|
}
|
|
h.ProfilePath = path
|
|
h.Engine.SetService(persistence.StoreID, save.NewStore(filepath.Join(filepath.Dir(path), "saves")))
|
|
data, err := platform.ReadProfile(path)
|
|
if err != nil {
|
|
ch.Warn("cannot read the player settings", log.F("path", path), log.F("err", err.Error()))
|
|
}
|
|
if lerr := h.Settings.LoadProfile(data, path); lerr != nil && len(data) > 0 {
|
|
_ = platform.WriteProfile(path+".bad", data)
|
|
ch.Warn("the player settings are damaged, a copy is kept as settings.aetext.bad", log.F("path", path))
|
|
}
|
|
h.Settings.SetPersist(func(b []byte) error { return platform.WriteProfile(path, b) })
|
|
}
|
|
|
|
func (h *Host) Close() {
|
|
if h.closed {
|
|
return
|
|
}
|
|
h.closed = true
|
|
if h.Engine != nil {
|
|
h.Engine.Close()
|
|
}
|
|
if h.Loader != nil {
|
|
h.Loader.Close()
|
|
}
|
|
if h.Pipeline != nil {
|
|
h.Pipeline.Close()
|
|
}
|
|
}
|