Stage 2: render pipeline and UI toolkit over gpu/platform. Stage 3: schema registry, asset pipeline + runtime loader, scene graph and ECS. Stage 4: editor — docking, inspector, scene/game views, play mode, asset browser, console, profiler; 4.5 adds the 3D foundation (mixed 2D/3D spaces, meshes, depth). Stage 5: Aego Script — compiler (lexer/parser/types/resolver/checker/asm/compiler), bytecode with verifier and register VM, instance runtime, stdlib, native bindings, and editor/CLI integration (aego run/edit/check/test/dump).
98 lines
1.5 KiB
Go
98 lines
1.5 KiB
Go
package asset
|
|
|
|
import (
|
|
"aego/core/handle"
|
|
"aego/core/ids"
|
|
"aego/render/mesh"
|
|
"aego/render/texture"
|
|
)
|
|
|
|
type assetTag struct{}
|
|
|
|
type Handle = handle.Handle[assetTag]
|
|
|
|
type Texture struct{}
|
|
|
|
type Scene struct{}
|
|
|
|
type Prefab struct{}
|
|
|
|
type Mesh struct{}
|
|
|
|
type Kind interface {
|
|
Texture | Scene | Prefab | Mesh
|
|
}
|
|
|
|
func kindName[T Kind]() string {
|
|
var zero T
|
|
switch any(zero).(type) {
|
|
case Texture:
|
|
return "texture"
|
|
case Scene:
|
|
return "scene"
|
|
case Prefab:
|
|
return "prefab"
|
|
case Mesh:
|
|
return "mesh"
|
|
}
|
|
return "unknown"
|
|
}
|
|
|
|
type Ref[T Kind] struct {
|
|
ID ids.AssetID
|
|
region texture.Region
|
|
gen uint32
|
|
ok bool
|
|
}
|
|
|
|
func NewRef[T Kind](id ids.AssetID) Ref[T] {
|
|
return Ref[T]{ID: id}
|
|
}
|
|
|
|
func (r *Ref[T]) AssetRefID() ids.AssetID {
|
|
return r.ID
|
|
}
|
|
|
|
func (r *Ref[T]) SetAssetRefID(id ids.AssetID) {
|
|
if r.ID == id {
|
|
return
|
|
}
|
|
r.ID = id
|
|
r.region = texture.Region{}
|
|
r.gen = 0
|
|
r.ok = false
|
|
}
|
|
|
|
func (r *Ref[T]) AssetKind() string {
|
|
return kindName[T]()
|
|
}
|
|
|
|
func (r *Ref[T]) IsZero() bool {
|
|
return r.ID.IsZero()
|
|
}
|
|
|
|
func (r *Ref[T]) Region(res Resolver) (texture.Region, bool) {
|
|
if res == nil || r.ID.IsZero() {
|
|
return texture.Region{}, false
|
|
}
|
|
if gen := res.Generation(); r.ok && r.gen == gen {
|
|
return r.region, true
|
|
}
|
|
reg, ok := res.Texture(r.ID)
|
|
if !ok {
|
|
r.ok = false
|
|
return texture.Region{}, false
|
|
}
|
|
r.region = reg
|
|
r.gen = res.Generation()
|
|
r.ok = true
|
|
return reg, true
|
|
}
|
|
|
|
func (r *Ref[T]) Mesh(res Resolver) (*mesh.Mesh, bool) {
|
|
if res == nil || r.ID.IsZero() {
|
|
return nil, false
|
|
}
|
|
return res.Mesh(r.ID)
|
|
}
|