diff --git a/app.go b/app.go index ba3ed9d..f94b34c 100644 --- a/app.go +++ b/app.go @@ -26,8 +26,8 @@ func NewApp() *App { // scheduler.SetFixedTimeStep(4 * time.Millisecond) app := &App{ - world: world, - scheduler: scheduler, + world: world, + scheduler: scheduler, } return app @@ -43,6 +43,7 @@ func (a *App) Run() { type Plugin interface { Initialize(world *ecs.World) } + func (a *App) AddPlugin(plugin Plugin) { plugin.Initialize(a.world) } diff --git a/go.mod b/go.mod index d09ed66..e3d0c6e 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/ungerik/go3d v0.0.0-20240502073936-1137f6adf7e9 github.com/unitoftime/beep v0.0.0-20241026233918-b83e337289e8 github.com/unitoftime/ecs v0.0.4-0.20250104145201-4bbe9d72f60c - github.com/unitoftime/glitch v0.0.0-20241226152421-0e5863c2be1d + github.com/unitoftime/glitch v0.0.0-20250104145909-ad673646faaf github.com/unitoftime/gotiny v0.0.0-20240915162236-e7a35021e769 github.com/unitoftime/intmap v0.0.0-20231203115433-9505126f7096 github.com/unitoftime/packer v0.0.0-20230818221437-1f2c1b1e4275 diff --git a/go.sum b/go.sum index 0163357..a38106b 100644 --- a/go.sum +++ b/go.sum @@ -37,8 +37,8 @@ github.com/unitoftime/cod v0.0.0-20241228160133-efe666697475 h1:m0K71y86gw7kbyQS github.com/unitoftime/cod v0.0.0-20241228160133-efe666697475/go.mod h1:Iufibv9gn5GJb4Qzkf8e8xaXOV77OgkrB5kkBZTEN+M= github.com/unitoftime/ecs v0.0.4-0.20250104145201-4bbe9d72f60c h1:Hn3mekxfD7p3zqZN2LzT8MeemfRMZRzdKy7+1yeCGkM= github.com/unitoftime/ecs v0.0.4-0.20250104145201-4bbe9d72f60c/go.mod h1:YmsHdpPA1CcSd7i6o2W3NgTwFJYI8G68GeGqKimMb3c= -github.com/unitoftime/glitch v0.0.0-20241226152421-0e5863c2be1d h1:ujKNn8QSdGXE4CVHTUH4Di309HuuIlXGl+yk0ugVQ68= -github.com/unitoftime/glitch v0.0.0-20241226152421-0e5863c2be1d/go.mod h1:8QQX+VRTfxdixHCn5bWXYWDrmRzGlEY964ERh3/YIF8= +github.com/unitoftime/glitch v0.0.0-20250104145909-ad673646faaf h1:trqN6GqPkGOF6QnsPfp9RX87earQ05A7YUcOmRDpUG8= +github.com/unitoftime/glitch v0.0.0-20250104145909-ad673646faaf/go.mod h1:PNiytmW1wtVkCpOSzHWopTHbGI5JLBUESNwn9jl9uuU= github.com/unitoftime/gotiny v0.0.0-20240915162236-e7a35021e769 h1:SjK7DZ+RQcLLZwuz9bOLPW59fAZfadztDFDVg3nSiCE= github.com/unitoftime/gotiny v0.0.0-20240915162236-e7a35021e769/go.mod h1:iq4kY4pPC8ZKztyei1pln4Fkk0BxQbyM1hICubHxoCo= github.com/unitoftime/intmap v0.0.0-20231203115433-9505126f7096 h1:ietNpHDGnFAyabqzzinz8zJW2rjx/0DLslU4hU4wNbU= diff --git a/render/camera.go b/render/camera.go index 101f74c..9993b53 100644 --- a/render/camera.go +++ b/render/camera.go @@ -18,7 +18,7 @@ type Camera2DBundle struct { func (c Camera2DBundle) CompWrite(w ecs.W) { cam := NewCamera2D(glm.CR(0), 0, 0) target := Target{ - draw: c.target, + draw: c.target, batch: c.target, } visionList := NewVisionList() @@ -28,8 +28,6 @@ func (c Camera2DBundle) CompWrite(w ecs.W) { visionList.CompWrite(w) } - - //cod:component type Camera struct { Camera glitch.CameraOrtho diff --git a/render/default.go b/render/default.go index 90c4726..28fa5a6 100644 --- a/render/default.go +++ b/render/default.go @@ -36,6 +36,7 @@ func (p DefaultPlugin) Initialize(world *ecs.World) { type VisionList struct { List []ecs.Id } + func NewVisionList() VisionList { return VisionList{ List: make([]ecs.Id, 0), @@ -48,7 +49,6 @@ func (vl *VisionList) Clear() { vl.List = vl.List[:0] } - //cod:component type Window struct { *glitch.Window @@ -58,19 +58,20 @@ type Window struct { type Sprite struct { Sprite *glitch.Sprite } + func (s Sprite) Bounds() glm.Rect { return s.Sprite.Bounds() } //cod:component type Target struct { - draw RenderTarget + draw RenderTarget batch glitch.BatchTarget // TODO: Indexed? } //cod:component type Visibility struct { - Hide bool // If set true, the entity will always be calculated as invisible + Hide bool // If set true, the entity will always be calculated as invisible Calculated bool } diff --git a/render/pass.go b/render/pass.go index c60cc43..9cd5f20 100644 --- a/render/pass.go +++ b/render/pass.go @@ -51,7 +51,9 @@ func CalculateVisibilitySystem(dt time.Duration, camQuery *ecs.View2[Camera, Vis query.MapId(func(id ecs.Id, gt *transform.Global, sprite *Sprite, vis *Visibility) { vis.Calculated = false - if vis.Hide { return } + if vis.Hide { + return + } mat := gt.Mat4() shape := spatial.Rect(sprite.Bounds(), mat) @@ -64,7 +66,6 @@ func CalculateVisibilitySystem(dt time.Duration, camQuery *ecs.View2[Camera, Vis }) }) - // TODO: Optimization if there are a lot of cameras: Preconfigure a spatial hash // chunkSize := [2]int{1024/8, 1024/8} // visionMap := spatial.NewHashmap[ecs.Id](chunkSize, 8) @@ -92,7 +93,7 @@ func (l *RenderPassList) Clear() { l.List = l.List[:0] } -type RenderTarget interface{ +type RenderTarget interface { glitch.Target glitch.BatchTarget Bounds() glm.Rect @@ -100,27 +101,26 @@ type RenderTarget interface{ type RenderPass struct { batchTarget glitch.BatchTarget - drawTarget RenderTarget - clearColor glm.RGBA - camera Camera // TODO: I feel like there could/should support multiple? - visionList VisionList + drawTarget RenderTarget + clearColor glm.RGBA + camera Camera // TODO: I feel like there could/should support multiple? + visionList VisionList } func CalculateRenderPasses(dt time.Duration, passes *RenderPassList, query *ecs.View3[Camera, Target, VisionList]) { passes.Clear() query.MapId(func(id ecs.Id, camera *Camera, target *Target, visionList *VisionList) { passes.Add(RenderPass{ - drawTarget: target.draw, + drawTarget: target.draw, batchTarget: target.batch, - camera: *camera, - visionList: *visionList, + camera: *camera, + visionList: *visionList, }) }) // TODO: Sort somehow? Priority? Order added? } - func ExecuteRenderPass(dt time.Duration, passes *RenderPassList, query *ecs.View2[transform.Global, Sprite]) { for _, pass := range passes.List { glitch.Clear(pass.drawTarget, pass.clearColor) @@ -130,8 +130,12 @@ func ExecuteRenderPass(dt time.Duration, passes *RenderPassList, query *ecs.View for _, id := range pass.visionList.List { gt, sprite := query.Read(id) - if gt == nil { continue } - if sprite == nil { continue } + if gt == nil { + continue + } + if sprite == nil { + continue + } mat := gt.Mat4() sprite.Sprite.DrawColorMask(pass.batchTarget, mat, glm.White) @@ -139,7 +143,6 @@ func ExecuteRenderPass(dt time.Duration, passes *RenderPassList, query *ecs.View } } - func RenderingFlushSystem(dt time.Duration, query *ecs.View1[Window]) { query.MapId(func(_ ecs.Id, win *Window) { win.Update() diff --git a/transform/transform.go b/transform/transform.go index 85883cc..e5322db 100644 --- a/transform/transform.go +++ b/transform/transform.go @@ -158,7 +158,9 @@ func ResolveHeirarchySystem(world *ecs.World) ecs.System { global.Transform = local.Transform } - if children == nil { return } + if children == nil { + return + } resolveTransform(query, children, global) }) })